* * *

Recent Posts

Pages: [1] 2 3 ... 10
1
Beginners / Re: Visual Pascal Community Edition
« Last post by Handoko on Today at 12:32:04 pm »
Among others - huge problem for me would be to learn certain libraries and approaches.
Me too, too lazy to learn new libraries. It's been a long time I wanted to learn BGRABitmap, but still haven't started. :-[

Here I wrote a quick demo showing how to do drawing, moving and make connection. You can download the source for testing.

Code: Pascal  [Select]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, sysutils, Forms, Controls, Graphics, Menus, ExtCtrls, ComCtrls;
  9.  
  10. type
  11.  
  12.   { VisualTree }
  13.   TVTComponentType = (Box, Circle, Connection);
  14.   TVTComponent = record
  15.     ComponentType  : TVTComponentType;
  16.     ComponentImage : TShape;
  17.     Connection1    : TShape;
  18.     Connection2    : TShape;
  19.   end;
  20.  
  21.   { TForm1 }
  22.  
  23.   TForm1 = class(TForm)
  24.     mniClearConnections: TMenuItem;
  25.     mniConnectTo: TMenuItem;
  26.     mniClearAll: TMenuItem;
  27.     mniSep: TMenuItem;
  28.     mniNewCircle: TMenuItem;
  29.     mniNewBox: TMenuItem;
  30.     mnuNew: TPopupMenu;
  31.     mnuComponent: TPopupMenu;
  32.     StatusBar1: TStatusBar;
  33.     procedure FormCreate(Sender: TObject);
  34.     procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
  35.       Shift: TShiftState; X, Y: Integer);
  36.     procedure FormPaint(Sender: TObject);
  37.     procedure mniClearAllClick(Sender: TObject);
  38.     procedure mniClearConnectionsClick(Sender: TObject);
  39.     procedure mniConnectToClick(Sender: TObject);
  40.     procedure mniNewBoxClick(Sender: TObject);
  41.     procedure mniNewCircleClick(Sender: TObject);
  42.   private
  43.     VTComponents: array of TVTComponent;
  44.     procedure VTCreateConnection(ConnectTo: TShape);
  45.  
  46.     // TShape events
  47.     var
  48.       TSMouseClicked: Boolean;
  49.       TSMouseClickedX: Integer;
  50.       TSMouseClickedY: Integer;
  51.       TSMouseConnectionStart: TShape;
  52.       TSMouseSelected: TShape;
  53.     procedure TSMouseDown(Sender: TObject; Button: TMouseButton;
  54.       Shift: TShiftState; X, Y: Integer);
  55.     procedure TSMouseEnter(Sender: TObject);
  56.     procedure TSMouseLeave(Sender: TObject);
  57.     procedure TSMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  58.     procedure TSMouseUp(Sender: TObject; Button: TMouseButton;
  59.       Shift: TShiftState; X, Y: Integer);
  60.   end;
  61.  
  62. var
  63.   Form1: TForm1;
  64.  
  65. implementation
  66.  
  67. {$R *.lfm}
  68.  
  69. { TForm1 }
  70.  
  71. procedure TForm1.FormCreate(Sender: TObject);
  72. begin
  73.   SetLength(VTComponents, 0);
  74.   TSMouseClicked         := False;
  75.   TSMouseConnectionStart := nil;
  76. end;
  77.  
  78. // Show a popup menu
  79. procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  80.   Shift: TShiftState; X, Y: Integer);
  81. begin
  82.   if (TSMouseConnectionStart <> nil) then Exit;
  83.   mnuNew.PopUp(Left + X, Top + Y);
  84. end;
  85.  
  86. // Draw all connections
  87. procedure TForm1.FormPaint(Sender: TObject);
  88. var
  89.   i: Integer;
  90. begin
  91.   for i := 0 to Length(VTComponents)-1 do
  92.     with VTComponents[i] do begin
  93.       if ComponentType <> Connection then Continue;
  94.       Self.Canvas.Line(Connection1.Left+30, Connection1.Top+30,
  95.         Connection2.Left+30, Connection2.Top+30);
  96.     end;
  97. end;
  98.  
  99. // Remove all VTComponents
  100. procedure TForm1.mniClearAllClick(Sender: TObject);
  101. var
  102.   i: Integer;
  103. begin
  104.   for i := 0 to Length(VTComponents)-1 do
  105.     VTComponents[i].ComponentImage.Free;
  106.   SetLength(VTComponents, 0);
  107.   Invalidate;
  108. end;
  109.  
  110. // Remove connections of the selected component
  111. procedure TForm1.mniClearConnectionsClick(Sender: TObject);
  112. var
  113.   Index : Integer;
  114.   i     : Integer;
  115. begin
  116.   repeat
  117.     Index := -1;
  118.     for i := 0 to Length(VTComponents)-1 do
  119.       with VTComponents[i] do begin
  120.         if ComponentType = Connection then
  121.           if (Connection1 = TSMouseSelected) or (Connection2 = TSMouseSelected) then begin
  122.             Index := i;
  123.             Break;
  124.           end;
  125.       end;
  126.     if (index >= 0) then begin
  127.       for i := Index to Length(VTComponents)-2 do
  128.         VTComponents[i] := VTComponents[i+1];
  129.       SetLength(VTComponents, Length(VTComponents) - 1);
  130.     end;
  131.   until (Index = -1);
  132.   Invalidate;
  133. end;
  134.  
  135. // Start a new connection
  136. procedure TForm1.mniConnectToClick(Sender: TObject);
  137. begin
  138.   TSMouseConnectionStart             := TSMouseSelected;
  139.   TSMouseConnectionStart.Brush.Color := clGreen;
  140.   StatusBar1.SimpleText              := 'Click the target component or the green one to cancel.';
  141. end;
  142.  
  143. // Create a box component
  144. procedure TForm1.mniNewBoxClick(Sender: TObject);
  145. var
  146.   NewBox : TShape;
  147.   Index  : Integer;
  148. begin
  149.   NewBox := TShape.Create(Self);
  150.   with NewBox do begin
  151.     Left         := Mouse.CursorPos.x - Self.ClientOrigin.x;
  152.     Top          := Mouse.CursorPos.y - Self.ClientOrigin.y;
  153.     Width        := 60;
  154.     Height       := 60;
  155.     Parent       := Self;
  156.     OnMouseDown  := @TSMouseDown;
  157.     OnMouseEnter := @TSMouseEnter;
  158.     OnMouseLeave := @TSMouseLeave;
  159.     OnMouseMove  := @TSMouseMove;
  160.     OnMouseUp    := @TSMouseUp;
  161.   end;
  162.   Index := Length(VTComponents);
  163.   SetLength(VTComponents, Index + 1);
  164.   with VTComponents[Index] do begin
  165.     ComponentType  := Box;
  166.     ComponentImage := NewBox;
  167.     Connection1    := nil;
  168.     Connection2    := nil;
  169.   end;
  170. end;
  171.  
  172. // Create a circle component
  173. procedure TForm1.mniNewCircleClick(Sender: TObject);
  174. var
  175.   NewCircle : TShape;
  176.   Index     : Integer;
  177. begin
  178.   NewCircle := TShape.Create(Self);
  179.   with NewCircle do begin
  180.     Left         := Mouse.CursorPos.x - Self.ClientOrigin.x;
  181.     Top          := Mouse.CursorPos.y - Self.ClientOrigin.y;
  182.     Width        := 60;
  183.     Height       := 60;
  184.     Shape        := stCircle;
  185.     Parent       := Self;
  186.     OnMouseDown  := @TSMouseDown;
  187.     OnMouseEnter := @TSMouseEnter;
  188.     OnMouseLeave := @TSMouseLeave;
  189.     OnMouseMove  := @TSMouseMove;
  190.     OnMouseUp    := @TSMouseUp;
  191.   end;
  192.   Index := Length(VTComponents);
  193.   SetLength(VTComponents, Index + 1);
  194.   with VTComponents[Index] do begin
  195.     ComponentType  := Box;
  196.     ComponentImage := NewCircle;
  197.     Connection1    := nil;
  198.     Connection2    := nil;
  199.   end;
  200. end;
  201.  
  202. // Create a new connection
  203. procedure TForm1.VTCreateConnection(ConnectTo: TShape);
  204. var
  205.   Count, i, j: Integer;
  206. begin
  207.  
  208.   TSMouseConnectionStart.Brush.Color := clWhite;
  209.   StatusBar1.SimpleText              := '';
  210.   Count                              := Length(VTComponents);
  211.  
  212.   // Make sure the connection hasn't already created
  213.   for i := 0 to Count-1 do
  214.     for j := 0 to Count-1 do
  215.       if ((VTComponents[i].Connection1 = TSMouseConnectionStart) and (VTComponents[j].Connection2 = ConnectTo)) or
  216.        ((VTComponents[j].Connection1 = TSMouseConnectionStart) and (VTComponents[i].Connection2 = ConnectTo)) then begin
  217.           TSMouseConnectionStart := nil;
  218.           Exit;
  219.         end;
  220.  
  221.   SetLength(VTComponents, Count + 1);
  222.   with VTComponents[Count] do begin
  223.     ComponentType  := Connection;
  224.     ComponentImage := nil;
  225.     Connection1    := TSMouseConnectionStart;
  226.     Connection2    := ConnectTo;
  227.   end;
  228.   TSMouseConnectionStart := nil;
  229.   Invalidate;
  230.  
  231. end;
  232.  
  233. // Show a popup menu or create a new connection or start dragging
  234. procedure TForm1.TSMouseDown(Sender: TObject; Button: TMouseButton;
  235.   Shift: TShiftState; X, Y: Integer);
  236. begin
  237.  
  238.   if not(Sender is TShape) then Exit;
  239.   TSMouseSelected := (Sender as TShape);
  240.  
  241.   // Right click
  242.   if (Shift = [ssRight]) and (TSMouseConnectionStart = nil) and (Length(VTComponents) > 1) then
  243.     mnuComponent.PopUp(Mouse.CursorPos.x, Mouse.CursorPos.y);
  244.  
  245.   // Left click
  246.   if (Shift = [ssLeft]) then begin
  247.     if (TSMouseConnectionStart <> nil) then
  248.       VTCreateConnection(TSMouseSelected);
  249.     TSMouseClickedX := X;
  250.     TSMouseClickedY := Y;
  251.     TSMouseClicked  := True;
  252.   end;
  253.  
  254. end;
  255.  
  256. // Highlight the TShape
  257. procedure TForm1.TSMouseEnter(Sender: TObject);
  258. begin
  259.   if not(Sender is TShape) then Exit;
  260.   if (Sender = TSMouseConnectionStart) then Exit;
  261.   (Sender as TShape).Brush.Color := clRed;
  262. end;
  263.  
  264. // Remove the highlight
  265. procedure TForm1.TSMouseLeave(Sender: TObject);
  266. begin
  267.   if not(Sender is TShape) then Exit;
  268.   if (Sender = TSMouseConnectionStart) then Exit;
  269.   (Sender as TShape).Brush.Color := clWhite;
  270. end;
  271.  
  272. // Dragging a TShape
  273. procedure TForm1.TSMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer
  274.   );
  275. begin
  276.   if not(Sender is TShape) or not(TSMouseClicked) then Exit;
  277.   (Sender as TShape).Left := (Sender as TShape).Left + X - TSMouseClickedX;
  278.   (Sender as TShape).Top  := (Sender as TShape).Top  + Y - TSMouseClickedY;
  279.   if (TSMouseClicked) then Invalidate; // Redraw connections
  280. end;
  281.  
  282. // Mouse release
  283. procedure TForm1.TSMouseUp(Sender: TObject; Button: TMouseButton;
  284.   Shift: TShiftState; X, Y: Integer);
  285. begin
  286.   TSMouseClicked := False;
  287. end;
  288.  
  289. end.

The code is easy to understand, it's less than 300 LOC. It uses TShape to solve the object picking problem, most parts of the code are for handling the TShape's mouse events.

It is not optimized and not suitable for professional use. I just want to show the idea that simple TShape can be used to solve the diagram drawing issue. Maybe some newbies can learn something from the code.
2
Third party / Re: CAD program written in Lazarus / FPC
« Last post by zamtmn on Today at 12:22:55 pm »
Edson
EvalExpres.pas double in Graficador-de-Funciones-3D and TitoCad
and cant compile
Quote
DefObjGraf.pas(53,31) Error: Identifier not found "TMotPoint"

benohb
>>Such as the Blender 3d program structure
I'm watching ideas in autocad

>>A lot of things . Calculate area .Advanced print settings like autocad
If you want, you can join, and realize your interests
3
General / Re: Compile Photoshop Pascal Code
« Last post by Thaddy on Today at 12:03:45 pm »
AFAIk macpas mode ==~ Think pascal. Not the other ones.
4
General / Re: Import excel to dbgird
« Last post by wp on Today at 10:54:48 am »
This is a example shortended from TvPlanIt which creates a table by means of ZEOS:
Code: Pascal  [Select]
  1. procedure TVpZeosDatastore.CreateTable;
  2. begin
  3.   FConnection.ExecuteDirect(
  4.     'CREATE TABLE Contacts ('+
  5.       'RecordID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, '+
  6.       'ResourceID INTEGER, ' +
  7.       'FirstName VARCHAR(50), '+
  8.       'LastName VARCHAR(50), '+
  9.       'Title VARCHAR(20) ,'+
  10.       'Category INTEGER, '+
  11.       'Birthdate DATE, '+
  12.       'Anniversary DATE, '+
  13.       'Company VARCHAR(50), '+
  14.       'Department VARCHAR(50), '+
  15.       'UserField VARCHAR(100) )'
  16.   );
  17. end;

5
General / Re: Import excel to dbgird
« Last post by flori on Today at 10:07:57 am »
Yes I  generalized the example for the ZEOS components.
Just BufDataset1.CreateDataset not generalized for the zeos. I do not know what its the equivalent.
ZReadOnlyQuery1.CreateDataset is not working.
6
Beginners / Re: Visual Pascal Community Edition
« Last post by Researching on Today at 08:18:54 am »
Edson,
Does it look sensible, to combine all your projects, to make a kind of visual IDE with modular structure on the base of them?
Will it be possible to shift to Lazarus later? Or it can stand just in parallel?
And yes, your native language is Spanish? em-m-m May be translation would be needed.

You mentioned some issues? Of what kind?.
BRGD
7
General / Re: Import excel to dbgird
« Last post by flori on Today at 08:07:39 am »
Thank you very much!I am very grateful for the work!!!!!!!!!!!!!
8
Beginners / Re: Visual Pascal Community Edition
« Last post by Researching on Today at 08:07:32 am »
An yes, taking some base from ZCAD, mantioned by Handoko - looks attractive.
9
Beginners / Re: Visual Pascal Community Edition
« Last post by Researching on Today at 08:03:16 am »
Good day, to everyone!!
 
I'd like to figure out how to make this project in a time of a month. :o
Well...
1. I'd like to find the work sequence, by which making this project will speed up it's own making.
2. GUI would consist of four parts:
--- Class to draw graphical entity (based on parameters). Entites given in a form of library with text files, so you can easily add/change them.
--- Class? to drillDown current entity / convert link to entity.
--- Class to drop present level to files (recursive)
--- Class Class to solve drawing and distributing entites and connectors on the drawing space. (would be the main trouble) it get's data from parser, and also sends data to DeployPackage.

3. DeployPackage:
(like a class ?) It monitors the "list" of entites in realtime and deploys it to file structure or back.
4. LanguageKeeper (class? or a long recursive(?) function)
It reads/writes LanguageSetting.ini and gives the DeployPackage instructions/data to convert graphicals to dirs/files.
5. Parser, that takes LanguageSetting.ini and converts it to DeplyPackage compatible format.
Actually, would be perfect, to reverse the source of Ramus and convert it visually to Lazarus source.


Another aproach to speed up the project developmnet, would be to create a parser for an existing UML tool (Would perfect - for BOUML ) or the same Ramus and then make an initial roundtrip with it.

how diffucult would it be to "convert" Ramus to Pascal?

About manHours... Is it possible, that in case a clear WBS  would be made for this project - it's implementation could attract many users of Lazarus to make separate parts of it?

If yes, I'd consider making the WBS like an XMnid mindmap for the whole project or may be a class diagram in any UML tool. then -> gitHub and start Community work.

Among others - huge problem for me would be to learn certain libraries and approaches. But may be there are professionals on the forum, that know the needed sources on they're fingertips ?
ANother question is... WM5/6 seem to be not suported anymore (since Laz 1.6.4) So what is the difference betw. 1.6.4 and 1.8.2 ... or later? I'd like to have a version of this tool in my pocket in future. Could the same source be used in different versions of Lazarus?
10
General / Re: Compile Photoshop Pascal Code
« Last post by x2nie on Today at 07:40:18 am »

Thanks you every body. Your answers enlighten me so much.

Read more: http://wiki.freepascal.org/TObject
then this too: http://wiki.freepascal.org/Object


1. What is advantage of using "Object" rather than "Class"
I'm answering from TP/FPC POV, not MacPas. Object is allocated on the stack, class is always on the heap. Object will be freed automatically when the function goes out of scope, class requires either garbage collection or explicit deallocation.
5. What the compiler they use to build/compile ?
MacPas compiler of that day for sure.
MacPas, I found nothing about it except that in fpc there is compiler-compatible-mod {$mode macpas}.
http://wiki.freepascal.org/Mode_MacPas
There is said: "Mode MacPas tries to be compatible with the Pascal dialects commonly used on Macintosh, that is THINK Pascal, Metrowerks Pascal and MPW Pascal. For tips on porting from traditional Mac Pascal compiler to Free Pascal, see Porting from Mac Pascal"
So, I think youre talking about any of compiler for mac. Never mind.


Thanks you every body, its enough and is satisfied my curiosity. In fact, the answers are beyond it  :o 8-)
Pages: [1] 2 3 ... 10

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus