Solved

Delphi 7 :: Have a WideString in Record

Posted on 2006-11-14
9
1,060 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

830 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