Technical Information Database TI1442D.txt - Getting a record member char array into a memo. Category :Delphi 1.x Platform :All Windows Product : Description: Handling large strings with the 16 bit Delphi product can be difficult. Especially when the strings are part of a record structure and you would like to flow them into a TMemo. This document shows how to create a record structure that has a 1000 character member and still write it out from a memo then read it back into a memo. The main thrust of the method is to use the GetTextBuf method of the memo. The record structure used is just a string and the array of 1000 chars, but it could be much more complex. unit URcrdIO; interface uses SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,dbtables; type TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; type TMyRec = record MyArray : array [1..1000] of char; mystr : string; end; var Form1: TForm1; MyRec : TMyRec; mylist : TStringlist; PMyChar : PChar; myfile : file; mb : TStream; implementation {$R *.DFM} procedure TForm1.Button1Click(Sender: TObject); begin assignfile(myfile, 'c:\testblob.txt'); rewrite(myfile,1); fillchar(MyRec.MyArray,sizeof(MyRec.MyArray),#0); pmychar:= MyRec.MyArray; StrPCopy(pmychar,memo1.text); Blockwrite(MyFile,MyRec,SizeOf(MyRec)); closefile(MyFile); end; procedure TForm1.Button2Click(Sender: TObject); begin assignfile(myfile, 'c:\testblob.txt'); reset(myfile,1); fillchar(MyRec.MyArray,sizeof(MyRec.MyArray),#0); Blockread(MyFile,MyRec,SizeOf(MyRec)); pmychar:= MyRec.MyArray; Memo1.SetTextBuf(pmychar); end; end. Reference: 3/30/99 1:21:06 PM
Last Modified: 01-SEP-99