![]() |
Eigene Kompo / Dynamisch erstellt / Form best. erkennen
hi,
wusste nich wie ich den titel nennen soll?!? also es geht darum: ich hab eine komponente entwickelt. diese binde ich dynamisch ein. wie kann ich jetzt folgendes realisieren: ich will dass wenn ich auf eine komponente klicke dessen eigenschaften über das form verändern können, also angenommen ich klick auf die komponente3 dann kann ich in ein edit die caption eingeben... ich hab leider garkeine ahnung wie ich das realisieren kann? vllt über messages? ich hab ehrlich gesagt garkeine ahnung achja die kompo is abgeleitet von tcustomcontrol... vielen dank im vorraus :) owo |
Re: Eigene Kompo / Dynamisch erstellt / Form best. erkennen
Moin owo,
ehrlich gesagt, habe ich bislang nicht verstanden, was Du überhaupt machen willst. :gruebel: |
Re: Eigene Kompo / Dynamisch erstellt / Form best. erkennen
Ich würde mir eine Variable machen.. z.B so:
Delphi-Quellcode:
Dann im OnClick deiner Komponenten schreibst du
var Selected: TMyCompo;
Delphi-Quellcode:
Dann machst du ein Button und ein Edit auf dein Formular
Selected := TMyCompo(Sender);
und in die Button OnClick procedure schreibst du dann sowas:
Delphi-Quellcode:
So würd ichs machen, aber ich glaube bei den Jedis is da nochwas dabei was vielleicht besser ist.. weiß aber nichtmehr wie das heißt...
Selected.Caption := Edit1.Text;
Gruß Neutral General |
Re: Eigene Kompo / Dynamisch erstellt / Form best. erkennen
hi ;)
also: ich habe eine komponente die anklickbar is und ein caption hat... wenn ich davon mehrere erstelle (dynamisch), möchte ich danach z.b. die caption von einem ändern. wie kann ich es jetzt realisieren dann wenn ich dann eine komponente anklicke deren caption ändere... also nehm mal an ich hab ein edit auf dem form und 3 von meinem komponenten. je nach dem welche komponente ich anklicke möchte ich über das eine edit die caption ändern... jetzt besser? :) |
Re: Eigene Kompo / Dynamisch erstellt / Form best. erkennen
Zitat:
|
Re: Eigene Kompo / Dynamisch erstellt / Form best. erkennen
hi
aber wenn ich in die form unit das selected definiere, dann kennt das ja meine komponenten unit garnicht in der ich das onclick definiere... |
Re: Eigene Kompo / Dynamisch erstellt / Form best. erkennen
Moin Owo,
redest Du jetzt Änderungen zur Lauf- oder zur Designzeit? |
Re: Eigene Kompo / Dynamisch erstellt / Form best. erkennen
Delphi-Quellcode:
Verstanden ? ;) *g*
TForm1 = class(TForm)
Edit1: TEdit; Button1: TButton; //... private { Private-Deklarationen } public DynMyKompo: Array[0..2] of TMyKompo; procedure MyOnClick(Sender: TObject); end; //... var Selected: TMyKompo; //... procedure TForm1.MyOnClick(Sender: TObject); begin Selected := TMyKompo(Sender); end; procedure TForm1.FormCreate(Sender: TObject); var i: Integer; begin for i:= 0 to 2 do begin DynMyKompo[i] := TMyKompo.Create(Self); DynMyKompo[i].Parent := Self; DynMyKompo[i].OnClick := MyOnClick; DynMyKompo[i].x := i*100; end; end; procedure TForm1.Button1Click(Sender: TObject); begin Selected.Caption := Edit1.Text; end; Gruß Neutral General |
Re: Eigene Kompo / Dynamisch erstellt / Form best. erkennen
Laufzeit!!
|
Re: Eigene Kompo / Dynamisch erstellt / Form best. erkennen
hmm aber ich hab schon ein onClick in der Komponente selbst definiert... soll ich dass dann einfach mitnehmen oder? oder kann ich irgendwie sowas wie inherited verwenden?? bzw nich onClick sonder heißt bei mir onButton(var msg: tmessage) mit message wm_lbuttondown
|
Re: Eigene Kompo / Dynamisch erstellt / Form best. erkennen
grml :roll:
Das dürfte egal sein.. Weil TCustomControls von Natur aus ein OnClick Erreignis haben das du im OI freischalten kannst indem du bei deiner Klasse unter published folgendes schreibst:
Delphi-Quellcode:
Naja egal ob die Property jetzt Published ist oder nicht kannst du trotzdem den Code benutzen den ich dir da geschrieben habe...
TMyKompo = class(TCustomControl)
private //... public // .. published property OnClick; end; |
Re: Eigene Kompo / Dynamisch erstellt / Form best. erkennen
hmm leider funktioniert das ganze nur wenn ich die message wm_lbuttondown von der anderen prozedur wegnehme... :( leider müsste ich das jetzt in eine prozedur packen? oder gibts noch ne andere lösung?
|
Re: Eigene Kompo / Dynamisch erstellt / Form best. erkennen
Naja das Problem ist grad das ich deine Komponente zu schlecht kenne um da jetzt mehr sagen zu können :|
|
Re: Eigene Kompo / Dynamisch erstellt / Form best. erkennen
das sollte kein problem sein :)
Delphi-Quellcode:
unit Shape3;
interface uses SysUtils, Classes, Controls, ExtCtrls, Graphics, Messages, Windows; type TShapeType = (stRechteck, stDreieck, stProzess); TMyShape = class(TCustomControl) private { Private declarations } FShape : TShapeType; FCaption : String; FSelected : Boolean; rx, ry, rXObj, rYObj, oH, oW, oL, oT : Integer; procedure SetShape(Value : TShapeType); procedure SetCaption(Value : String); procedure SetSelection(Value : Boolean); protected { Protected declarations } protected procedure Paint();override; protected procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X,Y: Integer); override; protected procedure MouseMove(Shift: TShiftState; X, Y: Integer); override; protected procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X,Y: Integer); override; procedure onExit(var msg:TMessage);message cm_exit; // protected procedure onClick(); procedure onButton(var msg:TMessage);message wm_lbuttondown; public { Public declarations } published { Published declarations } property Shape: TShapeType read FShape write SetShape; property Caption: String read FCaption write SetCaption; property Selected: Boolean read FSelected write SetSelection; property onClick; end; procedure Register; implementation procedure Register; begin RegisterComponents('Samples', [TMyShape]); end; procedure TMyShape.onExit(var msg:TMessage); begin self.Selected := false; end; procedure TMyShape.onButton(var msg:TMessage); begin self.Selected := true; self.SetFocus; rX := Mouse.CursorPos.X-Parent.Left-Self.Left; rXObj := rX - 4; rY := Mouse.CursorPos.Y-Parent.Top-Self.Top; rYObj := rY - 30; oH := self.Height; oW := self.Width; oT := self.Top; oL := self.Left; self.BringToFront; end; procedure TMyShape.SetShape(Value : TShapeType); begin FShape := Value; Invalidate; end; procedure TMyShape.SetCaption(Value : String); begin FCaption := Value; Invalidate; end; procedure TMyShape.SetSelection(Value : Boolean); begin FSelected := Value; if Value = True then Self.DoubleBuffered := true else Self.DoubleBuffered := False; Invalidate; end; procedure TMyShape.Paint(); var sw, sh: Integer; begin Canvas.Brush.Color := clWhite; Canvas.FillRect(Rect(0,0,self.Width, self.Height)); sw := self.Width -1; sh := self.Height -1; if(self.Shape = stRechteck) then self.Brush.Color := clBlue; if(self.Shape = stProzess) then self.Brush.Color := clRed; if(self.Shape = stDreieck) then self.Brush.Color := clYellow; Canvas.Brush.Color := self.Brush.Color; Canvas.Font.Color := $00FFFFFF; Canvas.Font.Style := [fsBold]; if Self.Shape = stRechteck then begin Canvas.Polygon([Point(4, 4), Point(Self.ClientWidth-4, 4), Point(Self.ClientWidth-4, Self.ClientHeight-4), Point(4, Self.ClientHeight-4)]); end; If Self.Shape = stDreieck then begin Canvas.Polygon([Point(4, Trunc(Self.ClientHeight / 2)), Point(Self.ClientWidth-4, 4), Point(Self.ClientWidth-4, Self.ClientHeight-4)]); end; If Self.Shape = stProzess then begin Canvas.Polygon([Point(4,4), Point(Trunc(0.85 * Self.Width),4), Point(Self.Width-4,Trunc(Self.Height / 2)), Point(Trunc(0.85 * Self.Width), Self.Height-4), Point(4,Self.Height-4), Point(Trunc(0.15*Self.Width),Trunc(Self.Height / 2))]); end; If Self.Selected = True then begin Canvas.Pen.Style := psDot; Canvas.Pen.Color := $00999999; Canvas.Brush.Style:= bsClear; Canvas.Polyline([ Point(0,0), Point(sw,0), Point(sw,sh), Point(0,sh), Point(0,0) ]); Canvas.Pen.Style := psSolid; Canvas.Pen.Color := $00000000; Canvas.Brush.Color := $00FFFFFF; //Ecken [] zeichnen Canvas.Rectangle(0,0,8,8); Canvas.Rectangle(self.ClientWidth-8,0,self.ClientWidth,8); Canvas.Rectangle(0,self.ClientHeight-8,8,self.ClientHeight); Canvas.Rectangle(self.ClientWidth-8,self.ClientHeight-8,self.ClientWidth,self.ClientHeight); Canvas.Rectangle(Trunc(self.Width /2)-4,0,Trunc(self.Width /2)+4,8); Canvas.Rectangle(Trunc(self.Width /2)-4,self.Height-8,Trunc(self.Width /2)+4,self.Height); Canvas.Rectangle(0,Trunc(Self.Height / 2)-4,8,Trunc(Self.Height / 2)+4); Canvas.Rectangle(self.Width-8,Trunc(Self.Height / 2)-4,self.Width,Trunc(Self.Height / 2)+4); end; Canvas.Brush.Style := bsClear; Canvas.TextOut(Trunc(self.Width / 2)-Trunc(Canvas.TextWidth(Caption) / 2), Trunc(self.Height / 2) - Trunc(Canvas.TextHeight(Caption) / 2), Self.Caption); end; procedure TMyShape.MouseDown(Button: TMouseButton; Shift: TShiftState; X,Y: Integer); begin { mp := ScreenToClient(Mouse.CursorPos); rX := Mouse.CursorPos.X-Parent.Left-Self.Left; rY := mp.Y; self.Caption := '.'+IntToStr(mp.X); oH := self.Height; oW := self.Width; oT := self.Top; oL := self.Left; } // Self.Selected := True; end; procedure TMyShape.MouseMove(Shift: TShiftState; X, Y: Integer); begin if ((ssLeft in Shift) AND (self.Selected = True)) then begin //links oben if ((rxObj < 9) AND (ryObj < 9)) then begin self.Top := round((Mouse.CursorPos.Y - Parent.Top - ry) / 5)*5; self.Left := round((Mouse.CursorPos.X - Parent.Left - rx) / 5)*5; self.Height := oH+(oT - self.Top); self.Width := oW+(oL - self.Left); //rechts oben end else if ((rxObj > oW-8) AND (ryObj < 9)) then begin self.Top := ((Mouse.CursorPos.Y - Parent.Top - ry) div 10)*10; self.Height := oH+(oT - self.Top); self.Width := ((Mouse.CursorPos.X - Parent.Left - oL + (oW-rX)) div 10)*10; //rechts unten end else if ((rxObj > oW-8) AND (ryObj > oH -8)) then begin self.Top := oT; self.Left := oL; self.Height := Round((Mouse.CursorPos.Y - Parent.Top - oT + (oH-rY)) / 5) * 5; self.Width := Round((Mouse.CursorPos.X - Parent.Left - oL + (oW-rX)) / 5) *5; //links unten end else if ((rxObj < 9) AND (ryObj > oH -8)) then begin self.Top := oT; self.Left := Mouse.CursorPos.X - Parent.Left - rx; self.Height := Mouse.CursorPos.Y - Parent.Top - oT + (oH-rY); self.Width := oW+(oL - self.Left); //mitte oben end else if ((rxObj > Trunc(oW / 2)-4) AND (rxObj < Trunc(oW / 2)+4) AND (ryObj < 9)) then begin self.Top := ((Mouse.CursorPos.Y - Parent.Top - ry) div 10)*10; self.Height := oH+(oT - self.Top); //mitte links end else if ((rxObj < 9) AND (ryObj > Trunc(oH/2) -4) AND (ryObj < Trunc(oH/2)+4)) then begin self.Left := ((Mouse.CursorPos.X - Parent.Left - rx) div 10)*10; self.Width := oW+(oL - self.Left); //mitte rechts end else if ((rxObj > oW-8) AND (ryObj > Trunc(oH/2) -4) AND (ryObj < Trunc(oH/2)+4)) then begin self.Width := ((Mouse.CursorPos.X - Parent.Left - oL + (oW-rX)) div 10)*10; //mitte unten end else if ((rxObj > Trunc(oW / 2)-4) AND (rxObj < Trunc(oW / 2)+4) AND (ryObj > oH -8)) then begin self.Top := oT; self.Height := ((Mouse.CursorPos.Y - Parent.Top - oT + (oH-rY))div 10)*10; //sonst verschiebe nur end else begin self.Left := (round((Mouse.CursorPos.X - Parent.Left - rX) / 10)) * 10; self.Top := (round((Mouse.CursorPos.Y - Parent.Top - rY) / 10)) * 10; end; end; end; procedure TMyShape.MouseUp(Button: TMouseButton; Shift: TShiftState; X,Y: Integer); begin end; end. |
Re: Eigene Kompo / Dynamisch erstellt / Form best. erkennen
Ehm setz mal als erste Zeile von jeder Message Procedure ein
Delphi-Quellcode:
Hab auch mal ne Kompo gebaut wo ich Probleme hatte und das hat alle Probleme gelöst :)^^
inherited;
Gruß Neutral General |
Re: Eigene Kompo / Dynamisch erstellt / Form best. erkennen
du bist klasse!!! :D
danke!!! |
Alle Zeitangaben in WEZ +1. Es ist jetzt 18:55 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz