Solved

Delphi 7 :: Have a WideString in Record

Posted on 2006-11-14
9
1,099 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
[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
  • 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
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!

 

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

Technology Partners: 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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month3 days, 11 hours left to enroll

630 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