dlking
asked on
How to write to high and low bytes of an element in a widestring
Hi,
I think this is an easy if you know how question. How do you write to the
high and low bytes of an element in a widestring array individually.
If you know of a way to convert strings to widestings without adding on an extra
00 byte to each character and just kind of "cramming the bytes" in then that would be just as good.
Thanks
David
I think this is an easy if you know how question. How do you write to the
high and low bytes of an element in a widestring array individually.
If you know of a way to convert strings to widestings without adding on an extra
00 byte to each character and just kind of "cramming the bytes" in then that would be just as good.
Thanks
David
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hi,
thanks a lot for your help
Bye
thanks a lot for your help
Bye
KE,
to 1): "If you know of a way to convert strings to widestings without adding on an extra
00 byte to each character and just kind of "cramming the bytes" in then that would be just as good."
--> I did this and so your point 1) is superfluous.
to 2) This kind of casting is superfluous as I have shown in my comment and you can easily follow by looking at the disassembly view while executing string code.
to 3) What's all this good for? Please, write a little demo program and look at the CPU window. Writing:
var
S: WideString;
begin
S := 'Blah';
S := S + 'Blah';
end;
results in this code sequence:
:
call @WStrAsgn
:
call @WStrCat
:
call @WStrClr
show it is simple nonsense what you wrote.
Please, be so kind and use COMMENTS instead of answers in particular if you either only repeat already given suggestions/solutions and/or if you aren't unsure and have not verified your own suggestion!
Ciao, Mike
to 1): "If you know of a way to convert strings to widestings without adding on an extra
00 byte to each character and just kind of "cramming the bytes" in then that would be just as good."
--> I did this and so your point 1) is superfluous.
to 2) This kind of casting is superfluous as I have shown in my comment and you can easily follow by looking at the disassembly view while executing string code.
to 3) What's all this good for? Please, write a little demo program and look at the CPU window. Writing:
var
S: WideString;
begin
S := 'Blah';
S := S + 'Blah';
end;
results in this code sequence:
:
call @WStrAsgn
:
call @WStrCat
:
call @WStrClr
show it is simple nonsense what you wrote.
Please, be so kind and use COMMENTS instead of answers in particular if you either only repeat already given suggestions/solutions and/or if you aren't unsure and have not verified your own suggestion!
Ciao, Mike
dlking,
WHAT ABOUT MY HELP???
WHAT ABOUT MY HELP???
ASKER
hi lischke,
I tried your suggestion but as i thought
it does add extra bytes. I think perhaps my question was not clear enough
what i wanted to do was to take a string of the form ( in bytes)
$a2 $67 $a3 $45
and create a widestring with exactly the same sequence ie not
$a2 $00 $67 $00 $a3 $00 $45 $00
which delphi does when it converts to
widestring.
At least my delphi 3 does.
Thanks though for your help and i'll try
and be clearer with my questions in future
Bye
I tried your suggestion but as i thought
it does add extra bytes. I think perhaps my question was not clear enough
what i wanted to do was to take a string of the form ( in bytes)
$a2 $67 $a3 $45
and create a widestring with exactly the same sequence ie not
$a2 $00 $67 $00 $a3 $00 $45 $00
which delphi does when it converts to
widestring.
At least my delphi 3 does.
Thanks though for your help and i'll try
and be clearer with my questions in future
Bye
Okay, but why did you then accept KE's answer which has nothing to do with your problem? For your problem you could esily use:
var
Buffer: array[0..1024] of Byte;
S: WideString;
begin
ReadBytesIntoBuffer(Buffer );
S := PWideChar(@Buffer);
end;
Quite easy, huh? :-)
Ciao, Mike
var
Buffer: array[0..1024] of Byte;
S: WideString;
begin
ReadBytesIntoBuffer(Buffer
S := PWideChar(@Buffer);
end;
Quite easy, huh? :-)
Ciao, Mike
ASKER
Hi,
KE's answer was useful - i did want to know how to manipulate the bytes etc
in the way he showed me. Your solution
above is also useful and tidier for the
actual string conversion so thats some points i owe you....
Thanks Again
David
KE's answer was useful - i did want to know how to manipulate the bytes etc
in the way he showed me. Your solution
above is also useful and tidier for the
actual string conversion so thats some points i owe you....
Thanks Again
David
Mike, I'm glad that you are watching me over the shoulder, but is it possible to do it a little more quiet ?
I've worked a LOT with WideStrings, actually from D3 and up. D3 and D4 did not handle WideStrings correctly so that's why I wrote these "idiot proof" typecasting's.
Load up your D3 (or D4) and try this example:
ws: WideString;
ws := some_wide_string_containin g_TRUE_wid echars
ws := ws + 'flaming out';
What you will get is a WideString where all TRUE widechars are converted to questionmarks = '?' = $2E as they would be in a normal WideString to String conversion.
However if you do as I describe:
ws := ws + WideString('flaming out');
your widestring will be CORRECTLY concatenated and contain it's original WideChars intact...
This is (what you may call) a BUG in the older versions...
BTW. This is the the first part of the question...
"How do you write to the high and low bytes of an element in a widestring array individually"
Where the HELL is your answer to that ???
And SORRY that I posted my comment as an answer - As I started on writing my answer I didn't see your comment, since it wasn't posted at that time - and I have to admit that I don't press refresh before submit - do you ?
Regards
PS. When I speak of TRUE WideChars I mean characters that is not within the bounds of a normal char.
PPS. I also think you are overreacting...
I've worked a LOT with WideStrings, actually from D3 and up. D3 and D4 did not handle WideStrings correctly so that's why I wrote these "idiot proof" typecasting's.
Load up your D3 (or D4) and try this example:
ws: WideString;
ws := some_wide_string_containin
ws := ws + 'flaming out';
What you will get is a WideString where all TRUE widechars are converted to questionmarks = '?' = $2E as they would be in a normal WideString to String conversion.
However if you do as I describe:
ws := ws + WideString('flaming out');
your widestring will be CORRECTLY concatenated and contain it's original WideChars intact...
This is (what you may call) a BUG in the older versions...
BTW. This is the the first part of the question...
"How do you write to the high and low bytes of an element in a widestring array individually"
Where the HELL is your answer to that ???
And SORRY that I posted my comment as an answer - As I started on writing my answer I didn't see your comment, since it wasn't posted at that time - and I have to admit that I don't press refresh before submit - do you ?
Regards
PS. When I speak of TRUE WideChars I mean characters that is not within the bounds of a normal char.
PPS. I also think you are overreacting...
ASKER
Hi,
KE's answer was useful - i did want to know how to manipulate the bytes etc
in the way he showed me. Your solution
above is also useful and tidier for the
actual string conversion so thats some points i owe you....
Thanks Again
David
KE's answer was useful - i did want to know how to manipulate the bytes etc
in the way he showed me. Your solution
above is also useful and tidier for the
actual string conversion so thats some points i owe you....
Thanks Again
David
KE, you may have right in many aspects here (in particular regarding overreaction), but the main problem is that you actually posted an ANSWER! There are only two cases when I post an answer. One is for questions like "How many is 2 + 2?" and the other is the questioneer requests it. How does it make sense to discuss questions if there's already an answer telling all other: "get out of here, I found this one first, this is mine, mine, mine"?
Proposing an answer should totally be disabled as it causes often frustration (not only for me :-)) and with the "accept comment as answer" option all what's needed is there. I'll suggest that to the EE stuff...
I have tried what you wrote regarding string casts with D4 and D5. Neither shows any unusual behaviour nor does they need explicit type casts, so the problem you mentioned might be caused by bugs in D3 and earlier.
Unfortunately, David didn't mention the Delphi version he's using, so it seems we both are true with our stuff. We had, though, discuss this normally if you hadn't proposed an answer in the first place...
Ciao, Mike
Proposing an answer should totally be disabled as it causes often frustration (not only for me :-)) and with the "accept comment as answer" option all what's needed is there. I'll suggest that to the EE stuff...
I have tried what you wrote regarding string casts with D4 and D5. Neither shows any unusual behaviour nor does they need explicit type casts, so the problem you mentioned might be caused by bugs in D3 and earlier.
Unfortunately, David didn't mention the Delphi version he's using, so it seems we both are true with our stuff. We had, though, discuss this normally if you hadn't proposed an answer in the first place...
Ciao, Mike
ASKER
Hi,
KE's answer was useful - i did want to know how to manipulate the bytes etc
in the way he showed me. Your solution
above is also useful and tidier for the
actual string conversion so thats some points i owe you....
Thanks Again
David
KE's answer was useful - i did want to know how to manipulate the bytes etc
in the way he showed me. Your solution
above is also useful and tidier for the
actual string conversion so thats some points i owe you....
Thanks Again
David
David, don't use the refresh button of your browser or you'll resend your last comment. There's a link "Reload Question" at the top of this page. Use this one instead :-)
Ciao, Mike
Ciao, Mike
Lische I agree that I shouldn't post my answer as the very first thing - you are right I should have posted a comment. Believe it or not, I normally do this. However I may have seen this question as a "2+2", since I've worked so much with WideStrings and especially BUGS concerning these. I'll try to remember not to post my answers so quickly as it will also leave other's out of the discussion - this is especially a problem if you give wrong answers - so I'm sorry.
Still, I think my answer is more complete than your's so I might have got the points anyway ;-)
Anyway, I can transfer the point to you, as I'm not here for the points - only for the excitement.
Regards
PS. No hard feelings - OK !
Still, I think my answer is more complete than your's so I might have got the points anyway ;-)
Anyway, I can transfer the point to you, as I'm not here for the points - only for the excitement.
Regards
PS. No hard feelings - OK !
Hi KE,
now that we cleared that I'm feeling much better :-) Okay, in this case you gave what was needed but often an (wrong) answer is given before even a discussion started and that's not the kind EE is working nor should it.
Ciao, Mike
PS: No need to transfer any points to me...
now that we cleared that I'm feeling much better :-) Okay, in this case you gave what was needed but often an (wrong) answer is given before even a discussion started and that's not the kind EE is working nor should it.
Ciao, Mike
PS: No need to transfer any points to me...
for converting a string to a wide string just use an assigment. Delphi will take care about the conversion:
var
S: String;
WS: String;
begin
S := 'Hallo';
WS := S;
// WS contains now a valid wide string
end;
Ciao, Mike