Delphi

<< Click to Display Table of Contents >>

Navigation:  Tutorials >

Delphi

1.Install CADEditorX.

2.Create a new VCL Forms application - Delphi:

clip0045

3.Save project in the CADEditorXTutorial folder; project name: CADEditorXTutorial.

4.Add to link to CADEditorLib_TLB to uses (You should add only the text written in bold type):

uses

 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

 Dialogs, CADEditorLib_TLB;

5.Add reference to CADEditorLib_TLB or copy it to the project directory (CADEditorXTutorial) from the CADEditorX Delphi demo.

6.Double-click the form and write the following code for the FormCreate event:

procedure TForm1.FormCreate(Sender: TObject);
begin
 SgCADEditor1 := TSgCADEditor.Create(Self);
 SgCADEditor1.Parent := Self;
 SgCADEditor1.Align := alClient;
end;

7.Add the private declarations SgCADEditor1: TSgCADEditor; to TForm1:

 TForm1 = class(TForm)

   procedure FormCreate(Sender: TObject);

 private

   { Private declarations }

  SgCADEditor1: TSgCADEditor;

8.Run the application.

clip0046

9.Close the application and change the code of FormCreate:

procedure TForm1.FormCreate(Sender: TObject);

begin

 SgCADEditor1 := TSgCADEditor.Create(Self);

 SgCADEditor1.Parent := Self;

 SgCADEditor1.Align := alBottom;

 SgCADEditor1.Height := 600;

 Height := 800;

end;

10. Add a button to the top of the form and set the “Draw line” caption:

clip0047

11.Double-click the button and add the following code (the const section and CADEditorX function call):

const
 CADXMLBegin: WideString = '<?xml version="1.0" encoding="UTF-16"?>'#13#10'<cadsofttools version="2.0">';
 CADXMLEnd: WideString = '</cadsofttools>';
procedure TForm1.Button1Click(Sender: TObject);
begin
 SgCADEditor1.ProcessXML(CADXMLBegin + '<command text="line"/>' + CADXMLEnd);
end;

12. Run the application and press the Draw Line button. As a result you can start drawing a line in the Editor window:

clip0048

The SgCADEditor1.ProcessXML function accepts parameters in XML format. You can find a lot of examples in the XML IDE application.

13. Add a new button with the Add Line caption as well as the following code:

procedure TForm1.Button2Click(Sender: TObject);
begin
 SgCADEditor1.ProcessXML(CADXMLBegin + '<add> <cstLine Point="0,0,0" Point1="10,0,0"/> </add> <FitToSize/>' + CADXMLEnd);
end;

consts CADXMLBegin and CADXMLEnd are the same as in the Draw Line button event handler.

14. Run the application and press the Add Line button. The line will be added:

tutorial-delphi

The Tutorial can be found in C:\Users\User\Documents\CADEditorX 14\Demos\Tutorial.

Go to CADEditorX