Solved

Delphi 7 :: Have a WideString in Record

Posted on 2006-11-14
9
1,025 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
 

Author Comment

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

WideChar := WhideStr


Thanks!
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now