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 typecastansistring toshortstring . 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)
|
分享到:
相关推荐
在C++builder中对AnsiString用法的一些总结,主要个人搜集整理的资料。
本人总结的最常用的AnsiString操作用法
AnsiString 使用大全.txt 适合初学者使用
这是讲解AnsiStirng类型字符串的用法的文档,里面提及了该类的诸多常用方法
procedure log4error(msg: AnsiString); //写ERROR级别的日志 procedure log4info(msg: AnsiString); //写INFO级别的日志 procedure log4debug(msg: AnsiString); //写DEBUG级别的日志 function log4filename():...
procedure log4error(msg: AnsiString); //写ERROR级别的日志 procedure log4info(msg: AnsiString); //写INFO级别的日志 procedure log4debug(msg: AnsiString); //写DEBUG级别的日志 function log4filename():...
基于ansistring类型开发了delphi7的高精度计算单元high.dcu,其中包含高精度加法、减法、乘法、除法、最小公倍数、最大公约数 等计算函数或过程。其接口文件如下: unit high; interface const intmax=32767; ...
delphi15 hint: frxGraphicUtils.pas(187) Warning: W1057 Implicit string cast from 'AnsiString' to 'string' delphi15 hint: frxGraphicUtils.pas(189) Warning: W1057 Implicit string cast from 'AnsiChar' to...
delphi 开发的UTF8 ansistring转换动态库。 通过DELPHI与C++测试。 前面上传的资源未经过仔细验证,有问题,不好意思,重新修正上传
* All string types(AnsiString, ShortString, String, String[XX], WideString) * Array type(with/without packed keyword), dynamic array and multidimensional dynamic array * Set type * Record type, ...
Delphi中String与WideString的区别2.docx
C++与C#间的函数替换,包括函数、变量以及其他相应的头文件转换。
AnsiString: Caption , AnsiString: Text, AnsiString: DisplayLabel, AnsiString: Hint,(当属性ShowHint为真时) TStrings: Items// 下拉框,列表框的 源程序在些公开,随便用,自己根据需要随便删改. -------------...
Delphi2007之前的API繁简转函数在Delphi2009版本出现后不能用,原因在于之前版本的String默认为AnsiString,而Delphi2007之后的String默认为WideString,同样,PChar指针也就为PAnsiString,所以调用Windows API函数...
1.实现utf8与ansiString的互转; 2.实现从指定UTF8文件中加载内容,返回ansiString串指针; 3.实现将ansiString保存成utf8文件;
先把WideString转换成AnsiString,然后再转换成PAnsiChar。直接使用PAnsiChar(mystring)可以编译通过,但运行不正确。思路的代码如下: var mysting:string;用 PAnsiChar(AnsiString(mysting))代替 pchar(mysting) ...
void compressFile(AnsiString srcDir, AnsiString dstFile) { ZipForge1->FileName = dstFile; ZipForge1->OpenArchive(); ZipForge1->BaseDir = srcDir; ZipForge1->AddFiles("*.*"); ZipForge1->...
function GBCht2Chs(GBStr: string): AnsiString; function GBChs2Cht(GBStr: string): AnsiString; implementation function GBCht2Chs(GBStr: string): AnsiString; {进行GBK繁体转简体} var Len: integer; ...
An AnsiString class reference
procedure qr(const AStr, AOut: AnsiString; AMargin, ASize, AEightBit,ACasesens, AStructured, ALevel, ACode: Integer; AFore, ABack: TColor); stdcall; external 'QRcode.dll'; //生成二维码图片 try qr...