Thema: Delphi Datensatz duplizieren

Einzelnen Beitrag anzeigen

Franz100

Registriert seit: 1. Aug 2005
17 Beiträge
 
#1

Datensatz duplizieren

  Alt 29. Jan 2010, 11:18
Datenbank: ABSdatabase • Zugriff über: datasource
Hallo

ich möchte mittels Button-Klick den aktuellen Datensatz kopieren. Dazu verwende ich folgenden Code (den ich im Forum gefunden habe)
Delphi-Quellcode:
procedure TForm1.SpeedButton2Click(Sender: TObject);
var
 Data: array of variant;
  aRecord: array of TVarRec;
  i: integer;
  max: integer;
  Marken: TDataSet;

   begin
  max := Marken.fields.count - 1;
  // set the lenghth of the arecord array to be the same as the number of
  // elements in the data array
  SetLength(arecord, max + 1);
  SetLength(data, max + 1);


  // set the variant type pointers to the data array
  for i := 0 to max do
  begin
    arecord[i].VType := vtVariant;
    arecord[i].VVariant := @data[i];
  end;


  // Copy the Record to the Array
  for i := 0 to max do
    Data[i] := Marken.fields[i].value;


  Marken.Insert;
  Marken.SetFields(aRecord);
end;
Läßt sich auf compilieren, nur wenn ich im Programm den Button anklicke, erhalte ich eine Zugriffsverletzung.
Weiß jemand wo es hakt?
  Mit Zitat antworten Zitat