Solved

Delphi 7 :: Have a WideString in Record

Posted on 2006-11-14
9
1,048 Views
Last Modified: 2010-05-18
Dear Experts,

I am using TTreeViewEx component which automates the process
of saving the TreeView's: Items, Images, Node.Data etc properties.

For this to work I need to declare a pointer to a Record containing all fields I want to store
in Node.Data.
The problem is that I need to be able to store fields of WideString type?
I realize can only do the following:

MyRecord = Record;
 UserName :String[255]   //Actually I need it to be of type: WideString
 UserSurname :String[255]
end;

Is store a solution to this?


Thanks!
0
Comment
Question by:Marius0188
  • 5
  • 4
9 Comments
 
LVL 19

Expert Comment

by:MerijnB
ID: 17941017
you can use array of widechar:

MyRecord = record
 UserName: array[1..255] of WideChar;
 UserSurname: array[1.255] of WideChar;
end;
0
 

Author Comment

by:Marius0188
ID: 17941152
How do I type cast it to WideString then?

For example:

var
  WideChar :Array[1..255] of WideChar;
  WideString :WideString;
begin
   WideString := WideChar; //This would not compile
end;


0
 
LVL 19

Expert Comment

by:MerijnB
ID: 17941323
I think your piece of code doesn't compile because you have named your WideString variable 'WideString'.
Try this:

var
  WideChar :Array[1..255] of WideChar;
  WideStr :WideString;
begin
   WideStr := WideChar;
end;
0
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 

Author Comment

by:Marius0188
ID: 17941346
And also the other way around.
For Example:

WideChar := WhideStr


Thanks!
0
 

Author Comment

by:Marius0188
ID: 17941422
Nope it was not the reason.
I just typed the example here in experts-exchange.
Bad example sorry.

I get the compiler error messages:
"Incompatibles types: 'Array' and 'WideString' "
0
 

Author Comment

by:Marius0188
ID: 17941435
Ok sorry I am wrong.

The problem is WideString to  Array of WideChar.

Example:

WCharArray := WideStr
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 17941623
I think this is easiest:

var WideArray: array [1..255] of widechar;
    WideStr: WideString;
begin
 WideStr := 'teststring';

 ZeroMemory(@WideArray[1], SizeOf(WideArray));
 CopyMemory(@WideArray[1], @WideStr[1], Length(WideStr) * SizeOf(WideChar));
end;
0
 

Author Comment

by:Marius0188
ID: 17941719
I get an EAccessViolation error when calling "CopyMemory....".
Something not working.

Let me explain what I am doing.

I have declared the following
------------------------------------------
Type
  PNodeData = ^TNodeData;
  TNodeData = Record;
     Url :Array[1..255] of WideChar;
end;
-----------------------------------------

Now when inserting a new TTreeNode in TTreeView I do the following:
----------------------------------------------------------------------------------
var
  Node :TTreeNode;
  NodeData :PNodeData;
  wsURL :WideString;
begin
  wsUrl := 'qwr34234234234234234234234234234234234324234234asdasd'; //For example purposes only
  GetMem(NodeData, SizeOf(TNodeData));
  NodeData^.Url := wsUrl;    //Problem here. Need to convert WideString to Array of WideChar or something.
                                        //And you code gives AccessViolation.
end;

----------------------------------------------------------------------------------
0
 
LVL 19

Accepted Solution

by:
MerijnB earned 500 total points
ID: 17941863
this works fine here ... ?

var
  wsURL :WideString;
  NodeData: PNodeData;
begin
  wsUrl := 'qwr34234234234234234234234234234234234324234234asdasd'; //For example purposes only
  GetMem(NodeData, SizeOf(TNodeData));

  ZeroMemory(@NodeData^.Url[1], SizeOf(NodeData^.Url));
  CopyMemory(@NodeData^.Url[1], @wsUrl[1], Length(wsUrl) * SizeOf(WideChar));
end;
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

773 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