re-jig two classes

Posted by Donald on March 27, 2007

Delphi 5 Pro. I have a problem! Two classes shown below. I hope this is clear and somebody could help me.
Sorry my first post is so long.

I have a zigzag line called TWire (TObject). To avoid the clickable area from being a surrounding rectangle for the whole zizgzag, which would overlap others, I created a second class TWseg (TGraphicControl). I have an array of 6 TWseg within TWire.
The end result is that the clickable area is only as thick as the line and follows it's contour. Also, which is essential, I can detect a mouse click on any segment and know which.
My problem is, when I click on a segment I cannot tell which wire it belongs to and am not too sure about the sender use.
I think the problem could be solved if I could get TWire to do the drawing of the segments, but still be able to detect which segment was clicked. The mouse events would need, presumably to be part of TWire not TWseg??? I tried making wire a TGraphicControl and making TWSeg a TObject to transfer the paint routine but got in a mess.HELP.

unit CWire;


uses windows, graphics, classes, math, controls, SysUtils, CWseg,contnrs,CTrack,CBody;

shstr = shortstring;

S: integer;
T: integer;
H: integer;

FLeft: Integer;
FTop: Integer;
FWidth: Integer;
FAxial: boolean;
Faligned: string;
Fwseg: array[1..6] of Twseg;
Fbody: TBody;
procedure SetLeft(value: Integer);
procedure SetTop(value: Integer);
procedure SetWidth(value: Integer);
procedure SetVend(value:integer);
procedure SetVsource(value:integer);
procedure SetAxial(value: boolean);
procedure SetAligned(value:string);
procedure SetVoltage(value: integer);
procedure SetBodywire(value:integer);
function getwseg(index: integer):Twseg;
procedure setwseg(index: integer; value:Twseg);
procedure setbody(value: Tbody);
Link: Array[1..2] of TLink;
constructor create;
constructor CreateFromStream(fs: Tfilestream);
destructor destroy;override;
property Left: Integer read FLeft write SetLeft;
property Top: Integer read FTop write SetTop;
property Width: Integer read FWidth write SetWidth;
property Axial: boolean read Faxial write setaxial;
property aligned: string read Faligned write Setaligned;

property wseg[index:integer]:Twseg read getwseg write setwseg;

unit CWseg;


uses windows, graphics, classes, math, controls, SysUtils;


FBrush: TBrush;
FPen: TPen;
FPoly: array[0..1] of TPoint;
Flength: integer;
Fmiddle: Tpoint;
Flimits: array[1..2] of integer;
FOrientation: char;
Fns: integer;
Few: integer;
Ftag: integer;
procedure SetPen(value: TPen);
procedure SetBrush(value: TBrush);
function GetPoly(Index: Integer): TPoint;
procedure SetPoly(Index: integer; value: TPoint);
//* procedure SetLink(value: TPlace);
procedure SetLimits(index: integer; value: integer);
function GetLimits(index: integer): integer;
procedure SetOrientation(value: char);
procedure Setns(value: integer);
procedure Setew(value: integer);

procedure Paint; override;
procedure StyleChange(sender: TObject); dynamic;
procedure MouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer);override;
procedure SetStubs;
constructor Create(AOwner: TComponent); override;
constructor CreateFromStream(fs: Tfilestream);
destructor Destroy; override;
property poly[Index: Integer]: Tpoint read GetPoly write SetPoly;

property length: integer read Flength;
property middle: Tpoint read Fmiddle;
property limits[index: integer]: integer read GetLimits write SetLimits;
property Orientation: Char read FOrientation write SetOrientation;
property ns: integer read Fns write Setns;
property ew: integer read Few write Setew;
property Brush: TBrush read FBrush write SetBrush;
property Pen: TPen read FPen write SetPen;

Related articles


Follow Ups