Autor Beitrag
hui1991
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 433

Windows XP, WIndows Vista
Turbo Delphi Explorer| Delphi, PHP,Blitzbasic
BeitragVerfasst: Fr 03.08.07 16:21 
Hallo,

ich habe mal versucht Variablen zuerstellen während der Laufzeit, dies habe ich mit Array und TStringlist geschafft, etz hat die Klasse aber ein Problem beim Create. Es macht ein Error. So sieht der Abschnitt aus:
ausblenden volle Höhe 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:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
type
  TValueTyp = Byte;

const
  StringValue: TValueTyp = 1;
  IntegerValue: TValueTyp = 2;
  DoubleValue: TValueTyp = 3;

  //Fehlerklassen
type
  EWrongVariable = class(Exception);
  EWrongVariableTyp = class(Exception);

  //Fehlerklassen

type
  TTypValues = Pointer;

type
  TTypValue = record
    Typen: TValueTyp;
  end;

type
  TFeldInteger = record
    FTyp: TTypValue;
    FFeld: Integer;
  end;

type
  TFeldExtended = record
    FTyp: TTypValue;
    FFeld: Double;
  end;

type
  TFeldString = record
    FTyp: TTypValue;
    FFeld: string;
  end;

type
  TFeld = record
    FFeldInteger: array of TFeldInteger;
    FFeldExtended: array of TFeldExtended;
    FFeldString: array of TFeldString;
  end;

type
  TMyList = class
  private
    FName: TStrings;
    FFeld: TFeld;
  public
    constructor Create;
    procedure Create2;
    procedure Free;
    function Count: Integer;
    procedure Add(TypValue: TValueTyp; NewValue: TTypValues; ValueName: string);
    procedure Delete(ValueName: string);
    procedure Clear;
    function GetStringValue(ValueName: string): string;
    function GetExtendedValue(ValueName: string): Double;
    function GetIntegerValue(ValueName: string): Integer;
    procedure SetValue(NewValue: TTypValues; ValueName: string);
  end;


Das hier ist der Constructor:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
constructor TMyList.Create;
begin
  inherited;
  try
  FName := TStringlist.Create; //Hier kommt der Fehler nach dem es ausgeführt wurde.
  SetLength(FFeld.FFeldInteger, 0);
  SetLength(FFeld.FFeldExtended, 0);
  SetLength(FFeld.FFeldString, 0);
  except
    ShowMessage('Zum Teufel nochmal warum kommt dieser Fehler?!');
  end;
end;


Das komische, wenn ich alles weg mache also das nur noch das hier da ist:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
constructor TMyList.Create;
begin //kommt hier der Fehler

end;


Da ich keine passenden Begriffe habe, kann ich nirgends suchen :(
Ich verzweifle schon dran, ich möchte weiter proggen, blos dieser Create Fehler versaut mir alles.
Alles was ich machen will, hängt mit dieser Klasse zusammen :(
Ich brauche eure hilfe.

MfG
hui1991

Moderiert von user profile iconChristian S.: b- durch highlight-Tags ersetzt
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 03.08.07 17:13 
Moin!

Hier mein Testprojekt mit deinem (Kern-)Code, allerdings etwas berichtigt:
ausblenden volle Höhe 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:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

const
  StringValue = 1;
  IntegerValue = 2;
  DoubleValue = 3;

type
  //Fehlerklassen
  EWrongVariable = class(Exception);
  EWrongVariableTyp = class(Exception);

  TValueTyp = Byte;

  TTypValues = Pointer;

  TTypValue = record
    Typen: TValueTyp;
  end;

  TFeldInteger = record
    FTyp: TTypValue;
    FFeld: Integer;
  end;

  TFeldExtended = record
    FTyp: TTypValue;
    FFeld: Double;
  end;

  TFeldString = record
    FTyp: TTypValue;
    FFeld: string;
  end;

  TFeld = record
    FFeldInteger: array of TFeldInteger;
    FFeldExtended: array of TFeldExtended;
    FFeldString: array of TFeldString;
  end;

  TMyList = class
  private
    FName: TStrings;
    FFeld: TFeld;
  public
    constructor Create;
    destructor Destroy; override;
  end;

  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TMyList }

constructor TMyList.Create;
begin
  inherited Create;
  try
    FName := TStringlist.Create;
    SetLength(FFeld.FFeldInteger, 0);
    SetLength(FFeld.FFeldExtended, 0);
    SetLength(FFeld.FFeldString, 0);
  except
    ShowMessage('Zum Teufel nochmal warum kommt dieser Fehler?!');
  end;
end;

destructor TMyList.Destroy;
begin
  FFeld.FFeldString := NIL;
  FFeld.FFeldExtended := NIL;
  FFeld.FFeldInteger := NIL;
  FName.Free;
  inherited;
end;

procedure TForm1.Button1Click(Sender: TObject);
  var
    tmp: TMyList;
begin
  tmp := TMyList.Create;
  tmp.Free;
end;

end.

So funktioniert´s jedenfalls; keine Exception beim Klick auf den Button. :nixweiss:

Tipp: Wenn du eine TStringList anlegst, dann solltest du auch eine solche Deklarieren, statt TStrings. :idea:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
hui1991 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 433

Windows XP, WIndows Vista
Turbo Delphi Explorer| Delphi, PHP,Blitzbasic
BeitragVerfasst: Fr 03.08.07 18:10 
Hi,

also ich hab alles so gemacht wie du und alles eingebunden blos beim Create vom TStringlist kommt bei mir immernoch eine Zugriffsverletzung :(
Ich weis net was der Fehler ist. Könnte das am OpenGL liegen das mit eingebunden ist?
Ich werde das mal in ein anderes Projekt stecken. Schauen was dann passiert.

Ergebniss, hier ist alles in ein neues Projekt gepackt:
ausblenden volle Höhe 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:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

const
  StringValue = 1;
  IntegerValue = 2;
  DoubleValue = 3;

type
  //Fehlerklassen
  EWrongVariable = class(Exception);
  EWrongVariableTyp = class(Exception);

  TValueTyp = Byte;

  TTypValues = Pointer;

  TTypValue = record
    Typen: TValueTyp;
  end;

  TFeldInteger = record
    FTyp: TTypValue;
    FFeld: Integer;
  end;

  TFeldExtended = record
    FTyp: TTypValue;
    FFeld: Double;
  end;

  TFeldString = record
    FTyp: TTypValue;
    FFeld: string;
  end;

  TFeld = record
    FFeldInteger: array of TFeldInteger;
    FFeldExtended: array of TFeldExtended;
    FFeldString: array of TFeldString;
  end;

  TMyList = class(TObject)
  private
    FName: TStrings;
    FFeld: TFeld;
  public
    constructor Create;
    destructor Destroy; override;
  end;

  type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  liste: TMyList;
  PIntegerV: Integer;
  PStringV: String;
  PDoubleV: Double;

implementation

{$R *.dfm}

//Listen bereich

destructor TMyList.Destroy;
begin
  FFeld.FFeldString := NIL;
  FFeld.FFeldExtended := NIL;
  FFeld.FFeldInteger := NIL;
  FName.Free;
  inherited;
end;

constructor TMyList.Create;
begin
  inherited Create;
  try
    FName := TStringlist.Create;
    SetLength(FFeld.FFeldInteger, 0);
    SetLength(FFeld.FFeldExtended, 0);
    SetLength(FFeld.FFeldString, 0);
  except
    ShowMessage('Zum Teufel nochmal warum kommt dieser Fehler');
  end;
end;

//Listen bereich

procedure TForm1.FormCreate(Sender: TObject);
begin
  liste.Create;
end;

end.


Das sollte eigentlich genau gleich sein wie von dir. Blos der Fehler ist immernoch beim FName := TStringlist.Create;
Das lustige ist, wenn ich das auskommentiere ist es auf der Zeile mit SetLength(FFeld.FFeldInteger, 0);.
Zeigt mir den Fehler, ich finde ihn leider nicht :(
Das Teil sollte doch gleich sein wie von dir :(

Hab das komplett mal als Archiv im Zipformat angehängt.

MfG
hui1991
Einloggen, um Attachments anzusehen!
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 03.08.07 19:57 
Moin!

user profile iconhui1991 hat folgendes geschrieben:
Zeigt mir den Fehler, ich finde ihn leider nicht

Aber gerne doch: :)
user profile iconhui1991 hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.FormCreate(Sender: TObject);
begin
  liste := TMyList.Create;
end;

"Kaum macht man´s richtig, geht´s!" :mahn: ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
hui1991 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 433

Windows XP, WIndows Vista
Turbo Delphi Explorer| Delphi, PHP,Blitzbasic
BeitragVerfasst: Fr 03.08.07 20:44 
Vielen Dank,

ich sollte lieber ein Programm erstellen das es vergleicht, blos naja ist auch Arbeit.
Vllt. mal genauer code vergleichen ^^
Naja kleiner Fehler -> große Wirkung

MfG
hui1991