細川さん・ありいさん・Kenさん
早い回答頂き有難うございます。
皆さんのご指摘されている、下記URLに色々有るのですが
http://leed.issp.u-tokyo.ac.jp/~takeuchi/delphi/browse.cgi?index=064757&back=http%3A%2F%2Fkakinotane.s7.xrea.com%2Fdelphi%2Ffaq%2Ff006.html
http://edn.embarcadero.com/jp/article/38791
http://kakinotane.s7.xrea.com/delphi/faq/f006.html
http://www.watercolor-city.net/ct_delphi/delphi_tiburon/doc_unicode/implict_convert.htm
もう一つ理解できません。
型キャストって、ある変数を別の型でオーバーラップするだけだと思っているのです。
Char型にPCharでキャストすれば、サイズが違うのでエラーに成りそうな気がするのですが。
Delphiコンパイラーは、厳格な型チェックを行ってくれるのに
以下は、明らかに間違いですが、コンパイルは通ります。
ch:Char;//Byte;integer;int64の時も
p :pointer;
p := pointer(ch);
p := pchar(ch);
Charは、Byteと同義なので通ってしまう様な気がします。
Pointer型のキャストは、対象が数値型なら何でもいいみたいですね。
ちょっと不細工なコーディングですが、キャストに付いて理解してる事を試してみました。
procedure TForm1.Button3Click(Sender: TObject);
Type
ArChar = Array[0..10] of Byte;
var
st : string;
pc : PChar;
sa : String;
begin
St := '01234567890';
St := '01234';
sa := intTohex(integer(@st), 8);
ShowMessage('文字列変数のアドレス= '+sa);
sa := intTohex(integer(pointer(st)^), 8);
ShowMessage('文字列変数の指す文字列へのアドレス= '+sa);
ShowMessage('文字列変数の指す文字列へのアドレスの実態= '
+intToHex(ArChar(pointer(st)^)[0], 2)
+intToHex(ArChar(pointer(st)^)[1], 2)
+intToHex(ArChar(pointer(st)^)[2], 2)
+intToHex(ArChar(pointer(st)^)[3], 2)
+intToHex(ArChar(pointer(st)^)[4], 2)
+intToHex(ArChar(pointer(st)^)[5], 2)
+intToHex(ArChar(pointer(st)^)[6], 2)
+intToHex(ArChar(pointer(st)^)[7], 2)
+intToHex(ArChar(pointer(st)^)[8], 2)
+intToHex(ArChar(pointer(st)^)[9], 2)
+intToHex(ArChar(pointer(st)^)[10], 2));
// 何故か、567890が無くなります。
St := '01234567890';
sa := intTohex(integer(@st), 8);
ShowMessage('文字列変数のアドレス= '+sa);
sa := intTohex(integer(pointer(st)^), 8);
ShowMessage('文字列変数の指す文字列へのアドレス= '+sa);
ShowMessage('文字列変数の指す文字列へのアドレスの実態= '
+intToHex(ArChar(pointer(st)^)[0], 2)
+intToHex(ArChar(pointer(st)^)[1], 2)
+intToHex(ArChar(pointer(st)^)[2], 2)
+intToHex(ArChar(pointer(st)^)[3], 2)
+intToHex(ArChar(pointer(st)^)[4], 2)
+intToHex(ArChar(pointer(st)^)[5], 2)
+intToHex(ArChar(pointer(st)^)[6], 2)
+intToHex(ArChar(pointer(st)^)[7], 2)
+intToHex(ArChar(pointer(st)^)[8], 2)
+intToHex(ArChar(pointer(st)^)[9], 2)
+intToHex(ArChar(pointer(st)^)[10], 2));
Pc := Pchar(st);
sa := intTohex(integer(pointer(pc)^), 8);
ShowMessage('PCHAR変数の指す文字列へのアドレス= '+sa);
ShowMessage('PCHAR変数の指す文字列へのアドレスの実態= '
+intToHex(ArChar(pointer(Pc)^)[0], 2)
+intToHex(ArChar(pointer(Pc)^)[1], 2)
+intToHex(ArChar(pointer(Pc)^)[2], 2)
+intToHex(ArChar(pointer(Pc)^)[3], 2)
+intToHex(ArChar(pointer(Pc)^)[4], 2)
+intToHex(ArChar(pointer(Pc)^)[5], 2)
+intToHex(ArChar(pointer(Pc)^)[6], 2)
+intToHex(ArChar(pointer(Pc)^)[7], 2)
+intToHex(ArChar(pointer(Pc)^)[8], 2)
+intToHex(ArChar(pointer(Pc)^)[9], 2)
+intToHex(ArChar(pointer(Pc)^)[10], 2));
ShowMessage('PCHAR変数'+pc);
ShowMessage('参照カウンタ'+intToStr(PLongInt(pc - SizeOf(LongInt)-
SizeOf(LongInt))^));
ShowMessage('文字数'+intToStr(PLongInt(pc - SizeOf(LongInt))^));
end;
----- Original Message -----
http://ad.freeml.com/cgi-bin/sa.cgi?id=jRydC
------------------------------------------------------[freeml byGMO]--