Solved

Records & Longstrings

Posted on 1997-11-26
3
161 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses
Course of the Month7 days, 21 hours left to enroll

617 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