Creating BLOG Record Type in Delphi Record Files

Hi

my TRecord Defination Goes like tis

BLOB_Record = PACKED Record
     BLOB_LENGTH : LONGINT;  //Length of the Text Field;
     BLOB_TEXT : ARRAY OF [0.65535] of CHAR;    
END;

Now here is my trouble, everytime i try to write the new record it adds junk characters in each record.

I need help i could avoid it by triming it. but not sure how to go about it.

Thanks
Anuj

qanujAsked:
Who is Participating?
 
MerijnBSr. Software EngineerCommented:
Maybe you mean something like:

var MyRecord: TRecord;
begin
 ZeroMemory(@MyRecord, SizeOf(TRecord));   // put 0's in the whole record
 ...
end;
0
 
ziolkoCommented:
try FillChar(BLOB_TEXT, SizeOf(BLOB_TEXT), 0);
before you write anything to BLOB_TEXT

ziolko.

0
 
ziolkoCommented:
got damn it! i'm few seconds too late again this morning:)

ziolko.
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
MerijnBSr. Software EngineerCommented:
lol :)
0
 
ziolkoCommented:
well i'm still thinking about EE t-shirt i received yesterday:)

ziolko.
0
 
qanujAuthor Commented:
Hi

This did help, partially. But the FileSize keeps increasing by 64Kb per record, and since some time the BLOB_text can be as small as 10-100 Characters only. Can be also trim it as we write it to only that lengh.

thanks
Anuj
0
 
qanujAuthor Commented:
Hi Ziolko

That also help, EE T-Shirt must have got lots of work from you.

thanks
Anuj
0
 
MerijnBSr. Software EngineerCommented:
do you write the whole record to the BLOB in the database?
The record itself has a size of 64kB, it just takes up that much space.
0
 
ziolkoCommented:
dont really get what you mean by "Can be also trim it as we write it to only that lengh"
BLOB_TEXT : ARRAY OF [0..65535] of CHAR;
means that you have fixed length field, if you want variable length
use array of char; but in this case you need call SetLength() which is of course more time consuming. consider using stream

ziolko.
0
 
ziolkoCommented:
qanuj -> lots of work but lots of fun too:)

ziolko.
0
 
MerijnBSr. Software EngineerCommented:
can't you use a memo field in the database instead of this blob field?
0
 
qanujAuthor Commented:
Yes, but is there a way to reduce yet have the freedom till 64Kb for the BLOB_text. my trouble is the file size, it will go HUGE... for 1000000+ Records
0
 
ziolkoCommented:
anyway... why string?:)

ziolko.
0
 
qanujAuthor Commented:
Is it possible to have Somethig equivelant to "Varchar" in TRecord
0
 
qanujAuthor Commented:
Array of char is not compatible data type for Record Files.

"dont really get what you mean by "Can be also trim it as we write it to only that lengh"
BLOB_TEXT : ARRAY OF [0..65535] of CHAR;
means that you have fixed length field, if you want variable length
use array of char; but in this case you need call SetLength() which is of course more time consuming. consider using stream"

I meant i want to reduce the length of char array while writing to record file. is it possible ?
0
 
ziolkoCommented:
ahh you got file of TRecord right?

ziolko.
0
 
MerijnBSr. Software EngineerCommented:
do you store binary data or only text in the file?
0
 
ziolkoCommented:
i'm afraid it's not possible with record files you need fixed length records.
and delphi will dump to file records of same size no matter of contents

ziolko.
0
 
qanujAuthor Commented:
Only text, its atually used for Storing "Comments" and "Notes" and "Remarks"
0
 
ziolkoCommented:
from delphi help:
"where fileTypeName is any valid identifier and type is a fixed-size type. Pointer types--whether implicit or explicit--are not allowed, so a file cannot contain dynamic arrays, long strings, classes, objects, pointers, variants, other files, or structured types that contain any of these."

ziolko.
0
 
MerijnBSr. Software EngineerCommented:
in case of text only, I'd just use a text file.
For easy going, you could even use a TStringlist to load and save the file (might get somewhat slow with lots and lots of records)
0
 
ziolkoCommented:
only text... maybe use TStringList :)

ziolko.
0
 
ziolkoCommented:
grrr merijn go get some coffee;)
ziolko.
0
 
MerijnBSr. Software EngineerCommented:
too slow again ziolko, get that T-Shirt out of your head!
btw, I'm still waiting for mine :p
0
 
diniludCommented:
procedure TForm1.BitBtn1Click(Sender: TObject);
type
   BLOB_Record = Record
     BLOB_LENGTH : LONGINT;  //Length of the Text Field;
     BLOB_TEXT :array[0..9] of char;
    END;
var x:BLOB_Record; S:String;
begin
x.BLOB_TEXT:='gfhfgf';
s:=x.BLOB_TEXT ;
ShowMessage(s+ '   -Length of x.BLOB_TEXT='+IntToStr(length(x.BLOB_TEXT))+
           '   -Length of s='+IntToStr(length(s)));
end;
0
 
diniludCommented:
procedure TForm1.BitBtn1Click(Sender: TObject);
type
   BLOB_Record = Record
     BLOB_LENGTH : LONGINT;  //Length of the Text Field;
     BLOB_TEXT :array[0..9] of char;
    END;
var x:BLOB_Record; S:PChar;
begin
x.BLOB_TEXT:='gfhfgf';
S:=@x.BLOB_TEXT;
ShowMessage(S+ '   -Length of x.BLOB_TEXT='+IntToStr(length(x.BLOB_TEXT))+
           '   -Length of s='+IntToStr(length(S)));
end;
0
 
MerijnBSr. Software EngineerCommented:
@ziolklo, guess what just arrived in the mail?
0
 
ziolkoCommented:
this time I was faster;)

p.s. i got blue one:)

ziolko.
0
 
developmentguruPresidentCommented:
 On the low level databases use a scheme where variable length fields (BLOB) are written to a second table and divided into chunks.  You add one record (ID 001) with the comment 'ABCDEFG'.  the comment is stored in a 256 byte (for example) field in a second table with a reference to this one.  You then add another (ID 002) with a a blob field that is a 1k JPG file.  It is stored in 4 records in the other table.  This is a loose description of how these databases go about avoiding storing a fixed size for fields that could be very large.  Your second table would require a reference to the first table and a field to determine the order, also a field to show the number of bytes used in each record.  This can be a fast means of accessing this type of data if you also have it indexed on ID + ORDER.  I hope this helps.
0
 
developmentguruPresidentCommented:
 As far as the junk characters... FillChar with 0 will eliminate the excess, but using what I stated in my last post, there would be no "extra".
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.