Autor Beitrag
Andreas Pfau
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 997



BeitragVerfasst: Di 01.07.03 22:18 
Hallo,

habe da einen Code gefunden:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
  TAVIFileOptions = object
                     Width, Height  : Integer;
                     Handler        : string[4];
                     Quality        : Integer;
                     FrameRate      : Integer;
                     Name           : string[63];
                     KeyFrameEvery  : Integer;
                     BytesPerSecond : Integer;
                     Flags          : Integer;
                     Compress       : Boolean;
                     ShowDialog     : Boolean;
                     procedure Init;
                    end;

Verwirrend... kein Create() kein Destroy(). Muss ich soche Deklarationen, also nicht "class" sondern "object", denn nicht initialisieren?

Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.

_________________
Life is a bad adventure, but the graphic is really good!
ErnestoChe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 528

Win 2000 pro, CRUX 2.0
Delphi 6 Pers, Open K3
BeitragVerfasst: Di 01.07.03 22:44 
Hi,

nur Klassen haben Konstruktoren und Destruktoren. Lies Dir am besten mal die Delphi-Hilfe unter Objekttypen durch. Das hilft Dir bestimmt weiter.

MFG

- Ernesto -
Böser Borstel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 154



BeitragVerfasst: Mi 02.07.03 08:16 
Titel: SelectObject, DeleteObject
SelectObject: ist doch die Initialisierung und damit es nicht zu viel Speicher frist würde ich das Objekt löschen (DeleteObject)
Andreas Pfau Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 997



BeitragVerfasst: Mi 02.07.03 12:51 
Hallo,

danke @ErnestoChe, habe nachgeschaut. Da steht, nicht zu empfehlen (Abwärtkompatibilität). Also, ich will eingeltich nur ein Record, aber der soll automatisch die Werte initialisieren können. Ein Klasse kann das zwar, die benötigt aber einen Konstruktor/Destruktor. Ein Object braucht das nicht wird ja aber nicht empfohlen. Einene Record kann man nicht initialisieren. Oder?

_________________
Life is a bad adventure, but the graphic is really good!
Böser Borstel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 154



BeitragVerfasst: Mi 02.07.03 13:30 
Titel: Record
Einen Record erstellt man mit Create und Löscht man mit Free!
Andreas Pfau Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 997



BeitragVerfasst: Mi 02.07.03 13:39 
Hallo,

waaaaaaaaas? Das habe ich noch nie gehört. Villeicht passiert das ja intern, aber ich muss Variablen eines Records NICHT initialisieren (nicht explizit). Es geht ja auch darum, dass ich eine Variabel brauche, mit Default-Werten, die man aber nicht initialisieren/deinitialisieren muss.

_________________
Life is a bad adventure, but the graphic is really good!
Böser Borstel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 154



BeitragVerfasst: Mi 02.07.03 13:47 
Titel: Record
Man kann einen Record initialisieren damit man den Speicher bei nicht Verwendung wieder freigeben kann. Du mußt es nicht aber dein Programm brauch dann mehr speicher.
Andreas Pfau Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 997



BeitragVerfasst: Mi 02.07.03 13:53 
Hallo,

aha, so ist das also. Aber, kann man die Variablen in einem Record auch initialisieren? Oder welchen Typ würdest du mir empfehlen?

_________________
Life is a bad adventure, but the graphic is really good!
ErnestoChe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 528

Win 2000 pro, CRUX 2.0
Delphi 6 Pers, Open K3
BeitragVerfasst: Mi 02.07.03 14:12 
Hi,

meinst Du sowas:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
type           // Deklaration

  MyRecord = record
    Alter: byte;
    Name: String;
    Ort: String;
  end;

//........................................................

var                            
  Rec: MyRecord;         // Instanziierung

//........................................................


procedure TForm1.FormCreate(Sender: TObject);
begin
  with Rec do                  // Initialisierung
  begin
    Alter := 25;
    Name := 'Horst';
    Ort := 'Irgendwo';
  end
end;

end;

MFG

- Ernesto -
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mi 02.07.03 14:16 
Titel: Re: Record
Böser Borstel hat folgendes geschrieben:
Einen Record erstellt man mit Create und Löscht man mit Free!

Das ist falsch.

Wenn ich eine Variable von einem Record brauchst du den Speicher nicht selbst verwalten.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
Type
  tMyRecord = Record
    Text,
    Text2: String
  End;

Var
  Test: tMyRecord;
Begin
  // Kein Create

  Test.Text := 'bla bla bal';

  // Kein Free
End;

Wenn du den das Record dynmaisch verwalten willst dann geht das so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
Type
  pMyRecord = ^tMyRecord;
  tMyRecord = Record
    Text,
    Text2: String
  End;

Var
  Test: pMyRecord;
Begin
  // Kein Create aber NEW

  New (Test);
  Test^.Text := 'bla bla bal';

  // Kein Free aber DISPOSE
  Dispose (Test);
End;
Andreas Pfau Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 997



BeitragVerfasst: Mi 02.07.03 15:37 
Hallo,

danke, @ErnestoChe, das ist aber nicht genau das, was ich suche. Ich stelle mir das so vor, dass ich eine Variable mit STANDARD-Wert habe, also:
ausblenden Quelltext
1:
2:
3:
4:
TSomething = record
  Int: Integer = 0;
  Str: String[3] = '123';
end;

geht so was?

_________________
Life is a bad adventure, but the graphic is really good!
maximus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: Mi 02.07.03 15:58 
Stell doch den compiler auf 'zuweisbare typisierte konstanten' und mach das so..

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
TSomething = record
  Int: Integer ;
  Str: String[3] ;
end;

const Something: TSomething = (int:0;str:'muku');


...is mir auch klar, dass das ungeil ist...wollt ich nur schonmal sagen

_________________
mfg.
mâximôv
Andreas Pfau Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 997



BeitragVerfasst: Mi 02.07.03 16:02 
Hallo,

jo, das hört sich schon besser an. Ist zwar wirklich "ungeil", aber das tut's mir. Danke!

_________________
Life is a bad adventure, but the graphic is really good!