Solved

Delphi 7 :: Have a WideString in Record

Posted on 2006-11-14
9
1,038 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
loading dll from external path 1 212
Delphi selector screen 2 70
tvirtualstringtree freeze when load too manny images 10 53
Dynamically Created Query 3 50
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…
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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

23 Experts available now in Live!

Get 1:1 Help Now