Autor Beitrag
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: Fr 25.04.08 21:34 
Hi,

Edit2: Sry hat sich erledigt, das Problem liegt wo anders.

Ich beschäftige mich gerade zum ersten Mal mit typisierten Dateien und habe bereits ein Tutorial dazu gelesen. Nur muss ich irgendetwas falsch verstanden oder übersehen haben, ich bekomme beim Laden eine Zugriffsverletzung, speichern klappt soweit.

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:
type
  TFormState = record
    Size: TRect;
    Visible: Boolean;
    WindowState: TWindowState;
  end;
  TFormStates = Array[FormIndex] of TFormState;
                
procedure SaveLayOut(const aFileName: String);
function TryLoadLayOut(const aFileName: String): Boolean;

implementation

procedure SaveLayOut(const aFileName: String);
var
  F: File of TFormStates;
  States: TFormStates;
  i: FormIndex;
  Frm: PForm;
begin
  for i := 0 to FormAnzahl - 1 do begin
    Frm := GlobalTraffic.Forms[i];
    States[i].Size := Rect(Frm^.Left, Frm^.Top, Frm^.Width, Frm^.Height);
    States[i].Visible := Frm^.Visible;
    States[i].WindowState := Frm^.WindowState;
  end;
  try
    AssignFile(F, aFileName);
    ReWrite(F);
    Write(F, States);
  finally
    CloseFile(F);
  end;
end;

function TryLoadLayOut(const aFileName: String): Boolean;
var
  F: File of TFormStates;
  States: TFormStates;
  i: FormIndex;
  Frm: PForm;
begin
  result := FileExists(aFileName);
  if result then begin
    try
      AssignFile(F, aFileName);
      Reset(F);
      Read(F, States);
    finally
      CloseFile(F);
    end;
    for i := 0 to FormAnzahl - 1 do begin
      Frm := GlobalTraffic.Forms[i];
      Frm^.Left := States[i].Size.Left;
      Frm^.Top := States[i].Size.Top;
      Frm^.Width := States[i].Size.Right;
      Frm^.Height := States[i].Size.Bottom;
      Frm^.Visible := States[i].Visible;
      Frm^.WindowState := States[i].WindowState;
    end;
  end;
end;


Edit: Ach so: GlobalTraffic ist ein globales Kommunikationsobjekt.

mfG,

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)