Autor Beitrag
Luzifer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98

WinXP Pro/ Vista
D5 Enterprise/D7 Enterprise/D2005 Architect
BeitragVerfasst: Di 19.04.05 15:10 
hi leutz, ich bin mal wieder und wieder mit ner Frage ;)

ich habe in einem prog mit der Create Methode Labels erstellt,

ausblenden Delphi-Quelltext
1:
Labelvar:=TLabel.create(form1)					


leider habe ich nun das problem, dass dieses label nicht in meiner form erscheint... delphi liefert aber auch keinen fehler......

thx for help!
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Di 19.04.05 15:17 
ausblenden Delphi-Quelltext
1:
2:
3:
Labelvar := TLabel.Create(nil);
Labelvar.Parent := Form1;
Labelvar.Caption := 'Beschriftung';

;)
Luzifer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98

WinXP Pro/ Vista
D5 Enterprise/D7 Enterprise/D2005 Architect
BeitragVerfasst: Di 19.04.05 15:19 
sehr gut, vielen dank!!!!!

geht das auch ohne ne "Labelvar" ??
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Di 19.04.05 15:21 
Wie meinst du das? :gruebel:
Luzifer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98

WinXP Pro/ Vista
D5 Enterprise/D7 Enterprise/D2005 Architect
BeitragVerfasst: Di 19.04.05 15:23 
naja meine frage ist eigentlich falsch gestellt, nicht ohne variable:

mein ziel ist, nicht nur ein Label zu erzeugen sondern mehrere hundert, und dafür müssten die variablen ja alle deklariert werden und durchlaufen..... geht sowas? also wenn ich die beispielsweise in einer for...to schleife durchlaufen lasse
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Di 19.04.05 15:30 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure CreateMyLabels;
var
  MyLabels: Array [1..100] of TLabel;
  i: Integer;
begin
  for i := 1 to 100 do begin
    MyLabels[i] := TLabel.Create(nil);
    MyLabels[i].Parent := Form1;
    end;
  //Anweisungen
  for i := 1 to 100 do
    MyLabels[i].Free;
end;

z.B. so... ;)

Dann einfach per
ausblenden Delphi-Quelltext
1:
MyLabels[5].Left := 300;					

den linken Abstand vom 5. Label ändern. Oder mit
ausblenden Delphi-Quelltext
1:
MyLabels[67].Caption := 'Ich bin das 67. Label! :)';					

die Beschriftung von diesem Label ändern. ;)
Luzifer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98

WinXP Pro/ Vista
D5 Enterprise/D7 Enterprise/D2005 Architect
BeitragVerfasst: Di 19.04.05 15:33 
ich danke dir! das hilft mir sehr viel weiter! (eigentlich bis zum ende!)

nur noch eine dumme frage: was bewirkt das free genau? ich habs in der hilfe nachgelesen, aber das versteh ich nicht.... :oops:
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Di 19.04.05 15:36 
Du erstellst während der Laufzeit deines Programms Komponenten per .Create... Die musst du dann auch irgendwann wieder freigeben, da sie sonst beim Programmende noch im Speicher bleiben. Bei Komponenten (wie z.B. Buttons), die du einfach per Maus auf das Formular ziehst, macht das Delphi automatisch. ;)

Aus der Hilfe:
Zitat:
Many of the objects you use in the Form Designer, such as buttons and edit boxes, are visible at both design time and runtime. Some, such as common dialog boxes, appear only at runtime. Still others, such as timers and data source components, have no visual representation at runtime.

You may want to create your own classes. For example, you could create a TEmployee class that contains Name, Title, and HourlyPayRate properties. You could then add a CalculatePay method that uses the data in HourlyPayRate to compute a paycheck amount. The TEmployee type declaration might look like this:

type
TEmployee = class(TObject)
private
FName: string;
FTitle: string;
FHourlyPayRate: Double;
public
property Name: string read FName write FName;
property Title: string read FTitle write FTitle;
property HourlyPayRate: Double read FHourlyPayRate write FHourlyPayRate;
function CalculatePay: Double;

end;

In addition to the fields, properties, and methods you've defined, TEmployee inherits all the methods of TObject. You can place a type declaration like this one in either the interface or implementation part of a unit, and then create instances of the new class by calling the Create method that TEmployee inherits from TObject:

var
Employee: TEmployee;
begin
Employee := TEmployee.Create;
end;

The Create method is called a constructor. It allocates memory for a new instance object and returns a reference to the object.

[highlight]Components on a form are created and destroyed automatically. However, if you write your own code to instantiate objects, you are responsible for disposing of them as well. Every object inherits a Destroy method (called a destructor) from TObject. To destroy an object, however, you should call the Free method (also inherited from TObject), because Free checks for a nil reference before calling Destroy. For example,

Employee.Free;

destroys the Employee object and deallocates its memory.[/highlight]
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Di 19.04.05 15:44 
TsTsTs Webspace.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.CreateMyLabels;
begin
  with TLabel.Create(self) do begin
    Parent := Form1;
    // Position sollte noch eingestellt werden
  end;
end;

Dann brauchst du das Free gar nicht. Den entsprechenden Text in der Hilfe hast du ja schon markiert.
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Di 19.04.05 15:46 
Nur NON-VCL-Kompos?? :eyes:
Luzifer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98

WinXP Pro/ Vista
D5 Enterprise/D7 Enterprise/D2005 Architect
BeitragVerfasst: Di 19.04.05 15:47 
hmm ich habe doch noch ein problem: bei mir wird immer nur das letzte label angezeigt....
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Di 19.04.05 15:48 
Die liegen wahrscheinlich alle übereinender... ;)
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Di 19.04.05 15:48 
Nein. Sie werden alle angezeigt. Die liegen alle nur übereinander, weil die die Position (left und top) noch nicht eingestellt hast. Deswegen mein Kommentar im Source.
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Di 19.04.05 15:53 
@jasocul:

user profile iconWeBsPaCe hat folgendes geschrieben:
Nur NON-VCL-Kompos?? :eyes:


;) Ja oder? Das meinen die mit "auf dem Formular liegend"... Oder?
Luzifer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98

WinXP Pro/ Vista
D5 Enterprise/D7 Enterprise/D2005 Architect
BeitragVerfasst: Di 19.04.05 15:56 
ihr hattet recht, sie lagen alle übereinander, ich hab das jetzt so gemacht:

ausblenden Delphi-Quelltext
1:
Labels[i].left := Labels[i].left + (30*i);					


jetzt stellt sich mir aber noch die frage: wenn i nun immer weiter steig (bis 100 zB) dann müsste der abstand zwischen den labels doch immer größer werden? tut er aber nicht? warum nicht?
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Di 19.04.05 15:57 
@webspace:
Das ist eine Frage des Owners.
Wenn der Owner die Form ist, wird beim Zerstören der Form auch der Destructor der damit verbunden Komponenten aufgerufen. Also aller Komponenten die als Owner die Form haben. Das können sowohl VCL als auch NON-VCL-Kompos sein.
Luzifer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98

WinXP Pro/ Vista
D5 Enterprise/D7 Enterprise/D2005 Architect
BeitragVerfasst: Di 19.04.05 15:57 
ah ok is schon gut, war nen denkfehler, die abstände werden ja immer von oben links gemessen und nicht vom vorlabel
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Di 19.04.05 15:59 
user profile iconjasocul hat folgendes geschrieben:
@webspace:
Das ist eine Frage des Owners.
Wenn der Owner die Form ist, wird beim Zerstören der Form auch der Destructor der damit verbunden Komponenten aufgerufen. Also aller Komponenten die als Owner die Form haben. Das können sowohl VCL als auch NON-VCL-Kompos sein.

Achso... Perfekt... ;)