![]() |
StringGrid speichern/Laden
Guten Abend zusammen,
kann mir jemand sagen wie ich ein StringGrid speichern und später wieder laden kann? Ich benutze Delphi 7 Personal. Danke schonmal im voraus ;) isofaind |
Re: StringGrid speichern/Laden
Eine StringGrid in eine Datei speichern kann man z.b. so: Auszug aus einem Projekt
Delphi-Quellcode:
procedure tabellespeichern;
type hdatei=record sp01,sp02,sp03,sp04,sp05,sp06,sp07,sp08,sp09,sp10,sp11, sp12,sp13,sp14,sp15,sp16,sp17,sp18,sp19,sp20,sp21,sp22, sp23,sp24,sp25,sp26,sp27,sp28,sp29,sp30,sp31:string[4]; sp32 :string[255]; {ex30} end; var f :file of hdatei; hdateiline :hdatei; x :integer; begin datei:=dateiname; assignfile(f,datei); {$I-} rewrite(f); {$I+} if ioresult=0 then begin for x:= 1 to 24 do begin {felder 1-31 in hdateiline einlesen-/-bemerkungen 24x abspeichern----} hdateiline.sp01:=form51.stringgrid1.cells[1,x]; hdateiline.sp02:=form51.stringgrid1.cells[2,x]; hdateiline.sp03:=form51.stringgrid1.cells[3,x]; hdateiline.sp04:=form51.stringgrid1.cells[4,x]; hdateiline.sp05:=form51.stringgrid1.cells[5,x]; hdateiline.sp06:=form51.stringgrid1.cells[6,x]; hdateiline.sp07:=form51.stringgrid1.cells[7,x]; hdateiline.sp08:=form51.stringgrid1.cells[8,x]; hdateiline.sp09:=form51.stringgrid1.cells[9,x]; hdateiline.sp10:=form51.stringgrid1.cells[10,x]; hdateiline.sp11:=form51.stringgrid1.cells[11,x]; hdateiline.sp12:=form51.stringgrid1.cells[12,x]; hdateiline.sp13:=form51.stringgrid1.cells[13,x]; hdateiline.sp14:=form51.stringgrid1.cells[14,x]; hdateiline.sp15:=form51.stringgrid1.cells[15,x]; hdateiline.sp16:=form51.stringgrid1.cells[16,x]; hdateiline.sp17:=form51.stringgrid1.cells[17,x]; hdateiline.sp18:=form51.stringgrid1.cells[18,x]; hdateiline.sp19:=form51.stringgrid1.cells[19,x]; hdateiline.sp20:=form51.stringgrid1.cells[20,x]; hdateiline.sp21:=form51.stringgrid1.cells[21,x]; hdateiline.sp22:=form51.stringgrid1.cells[22,x]; hdateiline.sp23:=form51.stringgrid1.cells[23,x]; hdateiline.sp24:=form51.stringgrid1.cells[24,x]; hdateiline.sp25:=form51.stringgrid1.cells[25,x]; hdateiline.sp26:=form51.stringgrid1.cells[26,x]; hdateiline.sp27:=form51.stringgrid1.cells[27,x]; hdateiline.sp28:=form51.stringgrid1.cells[28,x]; hdateiline.sp29:=form51.stringgrid1.cells[29,x]; hdateiline.sp30:=form51.stringgrid1.cells[30,x]; hdateiline.sp31:=form51.stringgrid1.cells[31,x]; if x<=12 then begin hdateiline.sp32:=bemerkungen[x]; end else begin hdateiline.sp32:='?'; end; {--------------------------------------------------------------------} seek(f,filesize(f));write(f,hdateiline); end; closefile(f); end else begin showmessage(datei+' Pfad nicht gefunden'); end; end; Laden könnte man so machen:
Delphi-Quellcode:
Im Beispiel wird ein Kalender geladen /gespeichert. Pro Tag gibt es zwei Felder.
procedure tabelleladen;
type hdatei=record sp01,sp02,sp03,sp04,sp05,sp06,sp07,sp08,sp09,sp10,sp11, sp12,sp13,sp14,sp15,sp16,sp17,sp18,sp19,sp20,sp21,sp22, sp23,sp24,sp25,sp26,sp27,sp28,sp29,sp30,sp31:string[4]; sp32 :string[255]; {ex30} end; var f :file of hdatei; hdateiline :hdatei; x,y :integer; begin nullsetzen; for x:= 1 to 31 do begin for y:= 1 to 24 do begin form51.stringgrid1.cells[x,y]:=''; end; end; datei:=dateiname assignfile(f,datei); {$I-} reset(f); {$I+} if ioresult=0 then begin for x:=1 to 24 do begin seek(f,x-1);read(f,hdateiline); {felder 1-31 in hdateiline einlesen-/-bemerkungen 24x laden ----} form51.stringgrid1.cells[1,x]:=hdateiline.sp01; form51.stringgrid1.cells[2,x]:=hdateiline.sp02; form51.stringgrid1.cells[3,x]:=hdateiline.sp03; form51.stringgrid1.cells[4,x]:=hdateiline.sp04; form51.stringgrid1.cells[5,x]:=hdateiline.sp05; form51.stringgrid1.cells[6,x]:=hdateiline.sp06; form51.stringgrid1.cells[7,x]:=hdateiline.sp07; form51.stringgrid1.cells[8,x]:=hdateiline.sp08; form51.stringgrid1.cells[9,x]:=hdateiline.sp09; form51.stringgrid1.cells[10,x]:=hdateiline.sp10; form51.stringgrid1.cells[11,x]:=hdateiline.sp11; form51.stringgrid1.cells[12,x]:=hdateiline.sp12; form51.stringgrid1.cells[13,x]:=hdateiline.sp13; form51.stringgrid1.cells[14,x]:=hdateiline.sp14; form51.stringgrid1.cells[15,x]:=hdateiline.sp15; form51.stringgrid1.cells[16,x]:=hdateiline.sp16; form51.stringgrid1.cells[17,x]:=hdateiline.sp17; form51.stringgrid1.cells[18,x]:=hdateiline.sp18; form51.stringgrid1.cells[19,x]:=hdateiline.sp19; form51.stringgrid1.cells[20,x]:=hdateiline.sp20; form51.stringgrid1.cells[21,x]:=hdateiline.sp21; form51.stringgrid1.cells[22,x]:=hdateiline.sp22; form51.stringgrid1.cells[23,x]:=hdateiline.sp23; form51.stringgrid1.cells[24,x]:=hdateiline.sp24; form51.stringgrid1.cells[25,x]:=hdateiline.sp25; form51.stringgrid1.cells[26,x]:=hdateiline.sp26; form51.stringgrid1.cells[27,x]:=hdateiline.sp27; form51.stringgrid1.cells[28,x]:=hdateiline.sp28; form51.stringgrid1.cells[29,x]:=hdateiline.sp29; form51.stringgrid1.cells[30,x]:=hdateiline.sp30; form51.stringgrid1.cells[31,x]:=hdateiline.sp31; if x<=12 then begin bemerkungen[x]:=hdateiline.sp32; end; {--------------------------------------------------------------------} end; closefile(f); form51.edit1.text:=bemerkungen[1];form51.edit2.text:=bemerkungen[2]; form51.edit3.text:=bemerkungen[3];form51.edit4.text:=bemerkungen[4]; form51.edit5.text:=bemerkungen[5];form51.edit6.text:=bemerkungen[6]; form51.edit24.text:=bemerkungen[7];form51.edit25.text:=bemerkungen[8]; form51.edit26.text:=bemerkungen[9];form51.edit27.text:=bemerkungen[10]; form51.edit28.text:=bemerkungen[11];form51.edit29.text:=bemerkungen[12]; end else begin end; end; Natürlich können die zwei Prozeduren nicht 1:1 verwendet werden. Es sind viele zusätzliche Sachen drin die du nicht brauchst. Aber evtl. zeigt dir das Beispiel wie du es selber lösen kannst... |
Re: StringGrid speichern/Laden
Forensuche schon bemüht?
|
Re: StringGrid speichern/Laden
Zitat:
|
Re: StringGrid speichern/Laden
Wie wärs das ganze mit einem array zu machen.
Du legst ein dynamisches Array of strings an und speicherst das ganze als .csv datei.(comma seperatet values.) Ich rate dir aber anstatt eines Kommas ein marschinelles Zeichen zu verwenden. (eins was keiner in einen String eingeben würde); oder du machst eine art exel datei draus(Exel ist so weit ich weis copyrighted also benutz lieber openoffice). Gruß snow |
Re: StringGrid speichern/Laden
|
Re: StringGrid speichern/Laden
Das beispiel nutz csv dateien.
Allerdings ist dies bei strings nicht sinnvoll, da strings selber kommas enthalten können. Sprich wenn dein user mal ein komma eingibt, dann haste ein problem. Daher benutz z.b ein solches zeichen ÿ Das wird fast nie benutz. oder schau in eine ascii oder unicode tabelle nach und such dir ein tolles, sinloses, veraltetes zeichen. Allerdings kannste dann nicht mit dem beispiel arbeiten sondern.
Delphi-Quellcode:
der code ist sehr knapp und unvollständig.
arrayxyz : array[0..spalten]of array[zeilen] of string;
datei : Textfile; begin for zeile:=0to zeilen do begin for spalte:=0tospalten do arrayxyz[zeile,spalte]:=stringgrid.cells[zeile,spalte]; end; AssignFile(Datei,'...\*.txt'); rewrite(datei); for zeile:=0 to zeilen do begin for spalte:=0 to spalten do dateistring:=dateistring+arrayxyz[zeile,spalte]+'ÿ'; end; writeln(dateistring); Datei.free; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 00:58 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