Solved

Records & Longstrings

Posted on 1997-11-26
3
158 Views
Last Modified: 2010-04-04
It is my understanding that items in a record can only hold up to 255 characters. I need to be able to store information in a record style structure, but I need longstring support. Is there are method to achieve this, either using records or some other structure?
0
Comment
Question by:JohnE
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
anilms earned 150 total points
ID: 1352030
Yes, you cannot have more than 255 characters in strings in records. We had a situation wherein the average number of characters to be stored was around 850. Using "String" instead of "String[900]" was not a proper solution. This is how we went about it :

1. New type definition for creating a string upto 1k :
  type
      kstring=record
        kslen:integer;
        ksdata:array[1..1024] of char
      end

2. Procedure to store any string in the kstring
   procedure putks(instring:string;var outks:kstring);
   begin
        outks.kslen := length(instring);
        move(instring[1],outks.ksdata,length(instring));
   end;

3. Function to assign a kstring to any string
   function getks(inks:kstring):string;
   var tmpstr:string;
   begin
        move(inks.ksdata,tmpstr[1],inks.kslen);
        SetLength(tmpstr,inks.kslen);
        getks := tmpstr;
   end;

4. You can now use this kstring anywhere in your records. Example :
  Type
   Emp_Rec = record
    Emp_Id:Cardinal;
    Emp_Name:string[40];
    Emp_Notes:KString
   end;

5. Accessing is also quite simple - examples
   Edit1.Text := getks(Emp_Name)
   PutKs(Emp_Name, Edit4.Text)  
0
 

Author Comment

by:JohnE
ID: 1352031
Thanks for your answer. I get the general idea of what is going on here, but am having trouble implementing the answer (storing string in kstring and then assigning kstring to a string). I get errors regarding the incompatibility between string and kstring or that acutal and formal parameters need to be identical.  Could you please give me a simple example of how to implement this. (I am very new to Delphi)?
0
 

Author Comment

by:JohnE
ID: 1352032
I have been able to implement this with error free code, but when I run ( a sample program see below), I always get a EAccessViolation error. It seems to be coming from the getks function?

Type
kstring = record
kslen: integer;
ksdata:array[1..1024] of char
end;

procedure putks(instring:string;var outks:kstring);
begin
outks.kslen := length(instring);
move(instring[1],outks.ksdata,length(instring));
end;

function getks(inks:kstring):string;
var
tmpstr:string;
begin
move(inks.ksdata,tmpstr[1],inks.kslen);
SetLength(tmpstr,inks.kslen);
getks := tmpstr;
end;

Type
Emp_Rec = record
Emp_Id:string[10];
Emp_Name:string[40];
Emp_Notes:kstring;
end;

var
Employee: Emp_Rec;

procedure TForm2.Button1Click(Sender: TObject);
begin
Employee.Emp_Id := Edit1.Text;
Putks(Edit1.Text, Employee.Emp_Notes);
end;

procedure TForm2.Button2Click(Sender: TObject);
begin
Memo1.Text := getks(Employee.Emp_Notes);
end;

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
tidtcpserver connection lost handle 2 109
Firemonkey allowing RTL on android 6 56
scroll down TListBox component in Delphi 1 31
Typecasting TBytes to Integer in Delphi XE8 2 34
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

762 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