![]() |
Re: Pointer Problem
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; |
Re: Pointer Problem
Was ist eigentlich TMacroCommand?
|
Re: Pointer Problem
Steht oben, das ist ein Record. Aber die andere interessante Frage ist: was ist TMacro? Klappt es evtl. so?
Delphi-Quellcode:
procedure TformEinstellungen.UpdateMacroLV(var Mac: TMacro);
|
Re: Pointer Problem
Wobei.. Meine Lösung wird wahrscheinlich auch nicht funktionieren. Deine TMacroCommand-Liste sollte PMacroCommand Pointer rausgeben, sonst gehts nicht.
|
Re: Pointer Problem
Also... nochmal zusammengefasst:
TMacro.Commands = PMacroCommand-Liste ! und dann:
Delphi-Quellcode:
procedure TformEinstellungen.UpdateMacroLV(Mac: TMacro);
var Cmd: PMacroCommand; begin LVMacro.Items.BeginUpdate; try LVMacro.Clear; // Alles wieder rein for Cmd in Mac.Commands do with LVMacro.Items.Add do begin Caption := frmMacro.cbCmdType.Items[Byte(Cmd^.CmdType)]; SubItems.Add(ArrayToStr(Cmd^.Parameters)); Data := Cmd; end; finally LVMacro.Items.EndUpdate; end; end; |
Re: Pointer Problem
@himitsu: Wenn es hilft, das ganze sieht so aus:
Delphi-Quellcode:
@jfheins, meinst du sowas (statt Data := @Cmd; in der Schleife):
TMacro = class;
TMacroCommand = record CmdType: TMacroCommandType; Parameters: TArrayofstring; AtTime: Boolean; Time: TTime; Macro: TMacro; end; PMacroCommand = ^TMacroCommand; TMacro = class public Name: string; Loop: Boolean; Commands: TList<TMacroCommand>; constructor Create; destructor Destroy; override; end;
Delphi-Quellcode:
Das funktioniert, allerdings geht p^.Macro.Commands.Remove(p^) dann nicht, weil p <> Cmd.
New(p);
p^.CmdType := Cmd.CmdType; p^.Parameters := Cmd.Parameters; p^.Macro := Cmd.Macro; Data := p; @Neutral General (1): Sowas ähnliches dachte ich mir. Aber direkt das Element in der Liste adressieren geht ja auch nicht.. @Neutral General (2): Oh gott. Aber eig eine gute Idee, werde ich mal probieren. Edit: Leute, ihr seid klasse! :dp: Mit TList<PMacroCommand> läuft nun alles wie es soll :-D |
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:47 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz