ERRORR MESSAGE GOT ANSISTRING EXPECTED SHORTSTRING

http://community.freepascal.org:10000/bboards/message?message_id=263454&forum_id=24083
 
 
 
Hello! Who an help me? I get the following error message in gimages.pp in line 271: Error: call by var parameters have to match exactly: Got ANSISTRING expected SHORTSTRING function LoadImage( Dir, FileName: string; var P: PImageCanvas; DesiredBPP: Word ): Boolean;   var     Dirr,Name,Ext: string;     R: PImageReader;     S: PStream;   begin     FSplit( FileName, Dirr, Name, Ext ); // here i get the error     FileName := FSearch( FileName, Dir+';'+Dirr+';'+'.\');     if FileName = '' then       begin         P := nil; The {$H+} directive brings no success. I tried two methods: 1.)   var   {$H+}  Dirr,Name,Ext: string; {$H-}   no success. I get the same error message. 2.)   I gave the {$H+} directive before LoadImage() function.   After LoadImage() function i gave {$H-} directive.   no success. I get the same error message. What goes wrong here? Thanks alredy for your help!
-- Thomas Sch ö nfelder,2007 년 11 월 22 일 10:48 오후
(E-mail)
 
답:
> Thanks alredy for your help! I hope this doesn't mean you aren't going to post a reply after someone helps. If the original poster doesn't reply after help is given, the person who helped has no idea whether his answer was read by the o.p. {$H+} is very cryptic; I had to look it up. {$longstrings on} is easier to understand. I had to look up "fsplit" also, but I didn't know which unit to look in. Using "dos.fsplit" would help readers of your program, especially since you left out the "uses dos" in the fragment above. Does the compiler directive {$longstrings on} or {$h+} appear anywhere else in your program? That would seem to be the problem. If so, you want to turn longstrings off (not on with {$h+}) when defining the function load_image. In the future, please show all compiler directives and "uses" that could affect the code that you post. This works for me:
{$longstrings on}

uses dos;

{$longstrings off}

procedure show_parts( file_name: string );
var dir,name,ext: string;
begin
  dos.fsplit( file_name, dir, name, ext );
  writeln( dir );
  writeln( name );
  writeln( ext );
end;

{$longstrings on}

var
  path: string;
begin
  path := 'c:\here\foo.bar';
  show_parts( path );
end.
Note that if the variable "path" is longer than 255 characters, only the first 255 charcters will be received by the procedure "show_parts", since its parameter is a short string. Another way to make sure that a string variable is a short string, not an ansistring, is to specify a maximal size:
var dir,name,ext: string[255];

-- Steve Fisher,2007 년 11 월 23 일 01:47 오전
(E-mail)
I noticed that it's possible to typecast  ansistring  to  shortstring . Try this:
FSplit( shortstring(FileName), shortstring(Dirr), shortstring(Name), shortstring(Ext) );

-- Mario Ray Mahardhika,2007 년 11 월 23 일 05:54 오전
(E-mail)
Hello! @Steve: Thank's for your help. To parenthise the used dos unit with the longstrings on/ff directive works for me. @Mario: The other version, the typecast to shortstring brings me the error message ...different type size (4 -> 256). Only the Steves version works for me. In spite of this, thank you too. You see, my "Thank's alredy for your help" doesn't mean that i don't replay an answer. I whish you both a nice weekend. Thomas
-- Thomas Sch ö nfelder,2007 년 11 월 23 일 10:59 오전
(E-mail)
The most standard / simplest solution obviously is changing the declaration to the following: var dir,name,ext: shortstring; The other option obviously is to add {$H-} or {$LONGSTRINGS OFF} before the declaration, that effectively does the same.
-- Tomas Hajny,2007 년 11 월 23 일 12:34 오후
(E-mail)
another possable answer is to use {R+} (openstring on) will cause all string passes to be flexable size this seems to help. you can deline a variable as openstring instead of string or shortstring.
-- Allen Harrington,2007 년 11 월 30 일 02:28 오후
(E-mail)

좋은 웹페이지 즐겨찾기