Ĺadny brzuch
pisze program który ma zapisywac duze ilosci tekstów do bazy baze mam na podstawie plików typowanych i nie moge do jednego pola w jednym rekordzie zapisac wiecej niz 255 znaków jak to ominac dla zobrazowania problemy przykładowy kod :
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Memo1: TMemo; Memo2: TMemo; zapisz: TButton; czytaj: TButton; czysc: TButton; dodaj: TButton; Edit1: TEdit; Edit2: TEdit; procedure czyscClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure dodajClick(Sender: TObject); procedure czytajClick(Sender: TObject); procedure zapiszClick(Sender: TObject); private { Private declarations } public { Public declarations } end; type Rnotatka = record tytul,text:string[255]; end; Tnotatka=array [1..50] of Rnotatka; var plik:file of Rnotatka; notatka:Tnotatka; text,tytul:ansistring; ilosc,index:integer; Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin Assignfile(plik , ExtractFilePath(Application.Exename) + 'notatka.dat'); {$i-} reset(plik); {$i+} if ioresult=0 then begin ilosc:=filesize(plik); for index:=1 to filesize(plik) do begin seek(plik,index-1); read(plik,notatka[index]); end; end else begin rewrite(plik); ilosc:=0; end; end; procedure TForm1.czyscClick(Sender: TObject); begin edit1.Text:=''; edit2.Text:=''; memo2.Text:=''; memo1.Text:=''; end; procedure TForm1.dodajClick(Sender: TObject); begin inc(ilosc); notatka[ilosc].tytul:=edit1.text; notatka[ilosc].text:=memo1.Text; end; procedure TForm1.czytajClick(Sender: TObject); begin edit2.text:=notatka[ilosc].tytul; memo2.Text:=notatka[ilosc].text; end; procedure TForm1.zapiszClick(Sender: TObject); begin closefile(plik); rewrite(plik); for index:=1 to ilosc do begin seek(plik,index-1); write(plik,notatka[index]); end; closefile(plik); end; end.
tytul,text: string[255]; zamien na tytul,text: string; i zaraz po implementation wpisz {$H+}
Użytkownik Kajetanek edytował ten post 14 grudzień 2005, 20:43
.... type Rnotatka = record tytul,text:string; end; Tnotatka=array [1..50] of Rnotatka; var Form1: TForm1; plik : file of Rnotatka; <-- to podkresla notatka:Tnotatka; text,tytul:ansistring; ilosc,index:integer; implementation {$H+} {$R *.dfm} ....
i wyrzuca taki błąd:
[Error] Unit1.pas(37): Type 'Rnotatka' needs finalization - not allowed in file type
Nie da się zrobić pliku typowanego z użyciem tablic o nieokreślonym rozmiarze (string) :)
Nie da się zrobić pliku typowanego z użyciem tablic o nieokreślonym rozmiarze (string) :)
to jak to zrobic ?
procedure TForm1.dodajClick(Sender: TObject); begin inc(ilosc); notatka[ilosc].tytul:=edit1.text; <-- to podkreśla notatka[ilosc].text:=memo1.Text; end;
nie pasuja mu typy taki kod błędu :
[Error] Unit1.pas(81): Incompatible types: 'TMyArray' and 'TCaption'
procedure TForm1.dodajClick(Sender: TObject); begin inc(ilosc); notatka[ilosc].tytul:=edit1.text; <-- to podkreśla notatka[ilosc].text:=memo1.Text; end;
nie pasuja mu typy taki kod błędu :
[Error] Unit1.pas(81): Incompatible types: 'TMyArray' and 'TCaption'
type TMyArray = array[0..1023]of char; procedure TForm1.Button1Click(Sender: TObject); var t:TMyArray; begin CopyMemory(@t,PChar(Edit1.Text+#0),Length(Edit1.Text)+1); Edit2.Text:=t; end;lubtype TMyArray = array[0..1023]of char; PMyArray = ^TMyArray; procedure TForm1.Button1Click(Sender: TObject); var t:TMyArray; begin t:=PMyArray(PChar(Edit1.Text))^; Edit2.Text:=t; end;
Użytkownik Cyrkiel edytował ten post 15 grudzień 2005, 07:12
Najlepiej zrób z tego funkcję aby nie pisać kilka razy tego samego kodu.
Użytkownik kAzek edytował ten post 15 grudzień 2005, 14:35
zanotowane.pl doc.pisz.pl pdf.pisz.pl zsf.htw.pl
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Memo1: TMemo; Memo2: TMemo; zapisz: TButton; czytaj: TButton; czysc: TButton; dodaj: TButton; Edit1: TEdit; Edit2: TEdit; procedure czyscClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure dodajClick(Sender: TObject); procedure czytajClick(Sender: TObject); procedure zapiszClick(Sender: TObject); private { Private declarations } public { Public declarations } end; type Rnotatka = record tytul,text:string[255]; end; Tnotatka=array [1..50] of Rnotatka; var plik:file of Rnotatka; notatka:Tnotatka; text,tytul:ansistring; ilosc,index:integer; Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin Assignfile(plik , ExtractFilePath(Application.Exename) + 'notatka.dat'); {$i-} reset(plik); {$i+} if ioresult=0 then begin ilosc:=filesize(plik); for index:=1 to filesize(plik) do begin seek(plik,index-1); read(plik,notatka[index]); end; end else begin rewrite(plik); ilosc:=0; end; end; procedure TForm1.czyscClick(Sender: TObject); begin edit1.Text:=''; edit2.Text:=''; memo2.Text:=''; memo1.Text:=''; end; procedure TForm1.dodajClick(Sender: TObject); begin inc(ilosc); notatka[ilosc].tytul:=edit1.text; notatka[ilosc].text:=memo1.Text; end; procedure TForm1.czytajClick(Sender: TObject); begin edit2.text:=notatka[ilosc].tytul; memo2.Text:=notatka[ilosc].text; end; procedure TForm1.zapiszClick(Sender: TObject); begin closefile(plik); rewrite(plik); for index:=1 to ilosc do begin seek(plik,index-1); write(plik,notatka[index]); end; closefile(plik); end; end.
tytul,text: string[255]; zamien na tytul,text: string; i zaraz po implementation wpisz {$H+}
Użytkownik Kajetanek edytował ten post 14 grudzień 2005, 20:43
.... type Rnotatka = record tytul,text:string; end; Tnotatka=array [1..50] of Rnotatka; var Form1: TForm1; plik : file of Rnotatka; <-- to podkresla notatka:Tnotatka; text,tytul:ansistring; ilosc,index:integer; implementation {$H+} {$R *.dfm} ....
i wyrzuca taki błąd:
[Error] Unit1.pas(37): Type 'Rnotatka' needs finalization - not allowed in file type
Nie da się zrobić pliku typowanego z użyciem tablic o nieokreślonym rozmiarze (string) :)
Nie da się zrobić pliku typowanego z użyciem tablic o nieokreślonym rozmiarze (string) :)

to jak to zrobic ?

procedure TForm1.dodajClick(Sender: TObject); begin inc(ilosc); notatka[ilosc].tytul:=edit1.text; <-- to podkreśla notatka[ilosc].text:=memo1.Text; end;
nie pasuja mu typy taki kod błędu :
[Error] Unit1.pas(81): Incompatible types: 'TMyArray' and 'TCaption'
procedure TForm1.dodajClick(Sender: TObject); begin inc(ilosc); notatka[ilosc].tytul:=edit1.text; <-- to podkreśla notatka[ilosc].text:=memo1.Text; end;
nie pasuja mu typy taki kod błędu :
[Error] Unit1.pas(81): Incompatible types: 'TMyArray' and 'TCaption'

type TMyArray = array[0..1023]of char; procedure TForm1.Button1Click(Sender: TObject); var t:TMyArray; begin CopyMemory(@t,PChar(Edit1.Text+#0),Length(Edit1.Text)+1); Edit2.Text:=t; end;lubtype TMyArray = array[0..1023]of char; PMyArray = ^TMyArray; procedure TForm1.Button1Click(Sender: TObject); var t:TMyArray; begin t:=PMyArray(PChar(Edit1.Text))^; Edit2.Text:=t; end;
Użytkownik Cyrkiel edytował ten post 15 grudzień 2005, 07:12
Najlepiej zrób z tego funkcję aby nie pisać kilka razy tego samego kodu.
Użytkownik kAzek edytował ten post 15 grudzień 2005, 14:35