ShortStrings and Delphi.Net

The Essentials component suite makes use of fixed length ShortStrings (String[10]) in various places. For the most part this seems to work just fine with Delphi.Net but there are places where the handling of ShortStrings seems to be buggy. There are a couple of reports in Quality Central concerning odd behaviour when using ShortStrings. Here are the links to the reports:

http://qc.codegear.com/wc/qcmain.aspx?d=62961
http://qc.codegear.com/wc/qcmain.aspx?d=62005

My problem was similar to this but different.


When the ShortString appears in the local variable list of an object’s method, calls to that method will throw an access violation. Changing the ShortString to a regular String (by just removing the [10] length specifier) make the problem go away. Oddly enough using the ShortString in a regular procedure call (not an object member) doesn’t seem to cause the problem.

Roughly what was happening in the code was this:

type
TMyClass = class
public
procedure MyMethod;
end;

procedure TMyClass.MyMethod;
var
s: String[10];
begin
end;

var
mc: TMyClass;

begin
mc := TMyClass.Create;
mc.MyMethod; ———–> This throws an access violation before the debugger can trace into the method.
end;

These problems all seem to be related. Hopefully, CodeGear will come up with a fix for this problem soon.

Leave a Reply