Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Creating BLOG Record Type in Delphi Record Files

Posted on 2007-07-24
30
Medium Priority
?
242 Views
Last Modified: 2010-04-05
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

0
Comment
Question by:qanuj
  • 12
  • 8
  • 6
  • +2
30 Comments
 
LVL 19

Accepted Solution

by:
MerijnB earned 2000 total points
ID: 19563200
Maybe you mean something like:

var MyRecord: TRecord;
begin
 ZeroMemory(@MyRecord, SizeOf(TRecord));   // put 0's in the whole record
 ...
end;
0
 
LVL 21

Expert Comment

by:ziolko
ID: 19563201
try FillChar(BLOB_TEXT, SizeOf(BLOB_TEXT), 0);
before you write anything to BLOB_TEXT

ziolko.

0
 
LVL 21

Expert Comment

by:ziolko
ID: 19563205
got damn it! i'm few seconds too late again this morning:)

ziolko.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 19

Expert Comment

by:MerijnB
ID: 19563211
lol :)
0
 
LVL 21

Expert Comment

by:ziolko
ID: 19563224
well i'm still thinking about EE t-shirt i received yesterday:)

ziolko.
0
 

Author Comment

by:qanuj
ID: 19563243
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
 

Author Comment

by:qanuj
ID: 19563250
Hi Ziolko

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

thanks
Anuj
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 19563252
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
 
LVL 21

Expert Comment

by:ziolko
ID: 19563266
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
 
LVL 21

Expert Comment

by:ziolko
ID: 19563268
qanuj -> lots of work but lots of fun too:)

ziolko.
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 19563272
can't you use a memo field in the database instead of this blob field?
0
 

Author Comment

by:qanuj
ID: 19563282
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
 
LVL 21

Expert Comment

by:ziolko
ID: 19563287
anyway... why string?:)

ziolko.
0
 

Author Comment

by:qanuj
ID: 19563298
Is it possible to have Somethig equivelant to "Varchar" in TRecord
0
 

Author Comment

by:qanuj
ID: 19563309
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
 
LVL 21

Expert Comment

by:ziolko
ID: 19563321
ahh you got file of TRecord right?

ziolko.
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 19563348
do you store binary data or only text in the file?
0
 
LVL 21

Expert Comment

by:ziolko
ID: 19563352
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
 

Author Comment

by:qanuj
ID: 19563357
Only text, its atually used for Storing "Comments" and "Notes" and "Remarks"
0
 
LVL 21

Expert Comment

by:ziolko
ID: 19563361
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
 
LVL 19

Expert Comment

by:MerijnB
ID: 19563367
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
 
LVL 21

Expert Comment

by:ziolko
ID: 19563368
only text... maybe use TStringList :)

ziolko.
0
 
LVL 21

Expert Comment

by:ziolko
ID: 19563374
grrr merijn go get some coffee;)
ziolko.
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 19563377
too slow again ziolko, get that T-Shirt out of your head!
btw, I'm still waiting for mine :p
0
 
LVL 10

Expert Comment

by:dinilud
ID: 19564061
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
 
LVL 10

Expert Comment

by:dinilud
ID: 19564085
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
 
LVL 19

Expert Comment

by:MerijnB
ID: 19564598
@ziolklo, guess what just arrived in the mail?
0
 
LVL 21

Expert Comment

by:ziolko
ID: 19564891
this time I was faster;)

p.s. i got blue one:)

ziolko.
0
 
LVL 21

Expert Comment

by:developmentguru
ID: 19576803
 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
 
LVL 21

Expert Comment

by:developmentguru
ID: 19576812
 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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question