Forum > KOL

KOL-CE File Write

(1/2) > >>

JoniDS:
hi,

I'am trying to write to a file in my win ce application.

This is the code :

//CODE

procedure TForm1.Button1Click(Sender: PObj);
var
dir : string;
f : thandle;
 msg : String;
begin
msg := 'hello world';

dir := extractfilepath(paramstr(0));

f := FileCreate(dir+'xpto.txt', ofCreateNew);
FileClose(f);
f := FileCreate(dir+'xpto.txt', ofopenwrite);
FileWrite(f, msg,sizeof(msg));
FileClose(f);

end;  

//CODE

It creates the file, but it writes nothing in it.
Can you tell me what's wrong?

Thanks in advance

aji:
This is how I write a line of text to a file that already exists:

[code]
 var n,i: integer;
     F : Textfile;
     buffer: string;
begin
     buffer:='';
     Assign(F, '\My Documents\test.txt'  );
     rewrite(F);
     Writeln(F,buffer) ;
     buffer:='';
     CloseFile(F) ;
[/quote]

stootch:

--- Quote from: "JoniDS" ---

--- Code: ---
f := FileCreate(dir+'xpto.txt', ofCreateNew);
FileClose(f);
f := FileCreate(dir+'xpto.txt', ofopenwrite);
FileWrite(f, msg,sizeof(msg));
FileClose(f);

--- End code ---


--- End quote ---

What GetLastError says after FileWrite?
Also, you don't have to close and instantly reopen the file once you have a handle.

yuriy_sydorov:
RTFM.

--- Code: ---FileWrite(f, PChar(msg)^,Length(msg));
--- End code ---

JoniDS:
Thanks,
I would gladly read the manual where is it?

Thanks for the tip :

FileWrite(f, PChar(msg)^,Length(msg));

However this way it still writes nothing to the file.
After some faild tentatives i managed to get it working by doing the following :
f := FileCreate(dir+'xptoa.txt', ofopenwrite or ofopenalways);

Not to abuse your help but now how do i write and read a RECORD?

Thanks again

Navigation

[0] Message Index

[#] Next page

Go to full version