AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Pointer Problem

Ein Thema von WorstNightmare · begonnen am 30. Sep 2009 · letzter Beitrag vom 30. Sep 2009
Antwort Antwort
Seite 2 von 2     12   
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
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.131 Beiträge
 
Delphi 12 Athens
 
#12

Re: Pointer Problem

  Alt 30. Sep 2009, 15:26
Was ist eigentlich TMacroCommand?
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.540 Beiträge
 
Delphi 11 Alexandria
 
#13

Re: Pointer Problem

  Alt 30. Sep 2009, 15:28
Steht oben, das ist ein Record. Aber die andere interessante Frage ist: was ist TMacro? Klappt es evtl. so?
procedure TformEinstellungen.UpdateMacroLV(var Mac: TMacro);
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat
Benutzerbild von Neutral General
Neutral General

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

Re: Pointer Problem

  Alt 30. Sep 2009, 15:30
Wobei.. Meine Lösung wird wahrscheinlich auch nicht funktionieren. Deine TMacroCommand-Liste sollte PMacroCommand Pointer rausgeben, sonst gehts nicht.
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
Benutzerbild von Neutral General
Neutral General

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

Re: Pointer Problem

  Alt 30. Sep 2009, 15:32
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;
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
WorstNightmare

Registriert seit: 6. Okt 2008
159 Beiträge
 
RAD-Studio 2010 Arc
 
#16

Re: Pointer Problem

  Alt 30. Sep 2009, 15:33
@himitsu: Wenn es hilft, das ganze sieht so aus:
Delphi-Quellcode:
  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;
@jfheins, meinst du sowas (statt Data := @Cmd; in der Schleife):
Delphi-Quellcode:
        New(p);
        p^.CmdType := Cmd.CmdType;
        p^.Parameters := Cmd.Parameters;
        p^.Macro := Cmd.Macro;
        Data := p;
Das funktioniert, allerdings geht p^.Macro.Commands.Remove(p^) dann nicht, weil p <> Cmd.

@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!
Mit TList<PMacroCommand> läuft nun alles wie es soll
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 2 von 2     12   


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 19:11 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz