Einzelnen Beitrag anzeigen

Benutzerbild von DGL-luke
DGL-luke

Registriert seit: 1. Apr 2005
Ort: Bad Tölz
4.149 Beiträge
 
Delphi 2006 Professional
 
#8

Re: Makro in Excel ausführen

  Alt 30. Jun 2006, 21:45
hallo, ich hab hier was absolut ungetestetes zusammengecodet.

Ich lade das ganze in einen Memorystream und greife mit ein wenig Pointer-Arithmetik direkt auf den Speicher zu. Ich suche nach ';', markiere mit meinen pointern anfang und ende, schiebe das in einen string und lade es in eien array. Der array ist übrigens [y,x] indiziert!

Delphi-Quellcode:
procedure TForm2.Load(fname: string);
var ms: TMemoryStream;
    row,col: Integer;
    b: string;
    values: array of array of Integer;
    ptrstart,ptrend,ptrEOF: Pointer;
begin
  ms := TMemoryStream.Create;
  ms.LoadFromFile(fname);
  row := 0;
  col := 0;

  setlength(values,rows,cols);

  ptrstart := @ms.memory;
  ptrEOF := Pointer(Integer(@ms.Memory) + ms.size);
  while not Integer(ptrstart) = Integer(ptrEOF) do
    begin
      ptrend := ptrstart;
      while not ((Integer(ptrend) = Integer(ptrEOF)) and (char(ptrend^) = ';')) do
        Inc(Integer(ptrend));
      if char(ptrend^) = ';then
        begin
          setlength(b,Integer(ptrend)-Integer(ptrstart)-1); //we don't want to get the '', too!
          CopyMemory(@b[1],ptrstart,length(b));

          ptrstart := Pointer(Integer(ptrend) + 1); // again +1 to skip the ';'

          values[row,col] := StrToIntDef(b,-1);

          Inc(col);
          if col = cols then
            begin
              col := 0;
              Inc(row);
              if row = rows then
                begin
                  setlength(values,Round(values * 1.72)+1,cols); // not sure about this... make sure the cols get allocated!
                  rows := length(values);
                end;
            end;
        end;
    end;
end;
Nochmal: Nicht getestet!

Ach ja genau, cols und rows muss unbedingt (global oder als parameter) gesetzt werden.
Lukas Erlacher
Suche Grafiktablett. Spenden/Gebrauchtangebote willkommen.
Gotteskrieger gesucht!
For it is the chief characteristic of the religion of science that it works. - Isaac Asimov, Foundation I, Buch 1
  Mit Zitat antworten Zitat