Thema: Delphi Pointer Problem

Einzelnen Beitrag anzeigen

Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#11

Re: Pointer Problem

  Alt 30. Sep 2009, 15:25
Ich glaube die for-in schleife ist das Problem. Du speicherst glaube ich wirklich nur die Adresse von deiner lokalen Cmd Variable. Das Cmd aus der For-schleife enthält also jeweils nur ne Kopie von dem jeweiligen Element in der Liste.

Probiers also mal so:

Delphi-Quellcode:
procedure TformEinstellungen.UpdateMacroLV(Mac: TMacro);
var Cmd: TMacroCommand;
    i: Integer;
begin
  LVMacro.Items.BeginUpdate;
  try
    LVMacro.Clear;

    // Alles wieder rein
    for i:= 0 to Mac.Commands.Count-1 do
      with LVMacro.Items.Add do
      begin
        Cmd := Mac.Commands[i];
        Caption := frmMacro.cbCmdType.Items[Byte(Cmd.CmdType)];
        SubItems.Add(ArrayToStr(Cmd.Parameters));

        Data := @Mac.Commands[i];
      end;
  finally
    LVMacro.Items.EndUpdate;
  end;
end;
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
  Mit Zitat antworten Zitat