![]() |
Procedure aus zweiter Unit
Hallo Leute
Ich möchte Im Endefekt mal ein PopupMenu für RichEdit erstellen in einer zweiten Unit, also das Ich das nicht immer alles neu erstellen muss sondern nur die Unit einbinden brauch. So nun zu meiner Frage, Ich mach das zum ersten mal(In Units auslagern). Habe nun mal erst zu Testzwecken ein label erzeugt aus der Unit_Label das klappt, nun wollt Ich die Profis mal fragen ob Ich Da auf dem richtigen Weg bin oder ob man das doch anders angehen sollte und ob das insoweit OK ist. HauptUnit
Delphi-Quellcode:
LabelUnit
unit Unit1;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; procedure Button2Click(Sender: TObject); private { Private-Deklarationen } LB:TLabel; public { Public-Deklarationen } end; var Form1: TForm1; implementation {$R *.dfm} uses Unit_Label; procedure TForm1.Button2Click(Sender: TObject); begin MakeLabel; end; end.
Delphi-Quellcode:
unit Unit_Label;
interface uses StdCtrls,Unit1; Procedure MakeLabel; implementation var LB:TLabel; Procedure MakeLabel; begin LB:=TLabel.Create(Form1); LB.Width:=100; LB.Height:=20; LB.Caption:='Testlabel'; LB.Top:=100; LB.Left:=100; LB.Parent:=Form1; end; end. |
Re: Procedure aus zweiter Unit
Um es flexibler zu gestalten, würde ich folgende Änderung einführen:
Delphi-Quellcode:
Procedure MakeLabel( AOwner, AParent: TComponent);
begin LB:=TLabel.Create( AOwner); ... LB.Parent := AParent; ... |
Re: Procedure aus zweiter Unit
Zitat:
Was sagt jetzt Owner aus MakeLabel(Form1,RichEdit); in etwa. Edit: habs mal ausprobiert LB.Parent:=AParent; Inkompatible Typen TWinControl und TComponent |
Alle Zeitangaben in WEZ +1. Es ist jetzt 20:28 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