“UTF8String = type string;” 什么意思??

IHatMyself 2012-02-13 11:36:38
RT
这样定义后 UTF8String 和 string 是啥关系??

我在用Delphi连接 SQLLite时,网上下的 pas文件中是这样的:

constructor TSQLiteDatabase.Create(const FileName: string);
var
Msg: PAnsiChar;
iResult: integer;
utf8FileName: UTF8string;
begin
inherited Create;
fParams := TList.Create;

self.fInTrans := False;

Msg := nil;
try
utf8FileName := UTF8String(FileName);
iResult := SQLite3_Open(PAnsiChar(utf8FileName), Fdb);

if iResult <> SQLITE_OK then

........


我这样使用:

slDBPath := ExtractFilepath(application.exename)+ 'test.db';
// slDBPath := 'test.db';
Memo1.Lines.Add(slDBPath);

sldb := TSQLiteDatabase.Create(slDBPath);

会报错 !!!


然后,我把 “constructor TSQLiteDatabase.Create(const FileName: string);”的源码改掉,改成如下:

constructor TSQLiteDatabase.Create(const FileName: string);
var
Msg: PAnsiChar;
iResult: integer;
// utf8FileName: UTF8string;
begin
inherited Create;
fParams := TList.Create;

self.fInTrans := False;

Msg := nil;
try
// utf8FileName := UTF8String(FileName);
// iResult := SQLite3_Open(PAnsiChar(utf8FileName), Fdb);
iResult := SQLite3_Open(PAnsiChar(FileName), Fdb);

......

就没错了......!!!

求指教 !!
PS : 是 Delphi6
...全文
343 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
CatSmoking 2012-02-14
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20111220/09/5786246f-4054-4e14-aff4-6f8906ff2167.html
有人讨论过了。
lzg827 2012-02-13
  • 打赏
  • 举报
回复
好神奇,我下的SQLLite的pas文件里面没有UTF8String
IHatMyself 2012-02-13
  • 打赏
  • 举报
回复
貌似是不是 传参时 用了const 然后在后面 强制类型转换时 就造成错误了??即 强转 const string 参数造成的错误?
IHatMyself 2012-02-13
  • 打赏
  • 举报
回复
那为何会出错?我改过后又不出错了?
funxu 2012-02-13
  • 打赏
  • 举报
回复
详细些说意思是用新的名字来替代string而且它确保在运行时,这个类型的变量被识别为它的新类型名称,而不是原先已存在的类型名称。
funxu 2012-02-13
  • 打赏
  • 举报
回复
他就是个string,不过会确保把所有的string类型替换为UTF8String
IHatMyself 2012-02-13
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 oraclers 的回复:]
Type
TMyInteger = Integer;
這種定義,TMyInteger與Integer是同一個類型,都可以當Integer用。

type
TMyInteger = type Integer;

這個在Integer前加了Type的,TMyInteger與Integer就是不同的類型了。
[/Quote]
那是哪里不同呢??内存存在形式?还是啥?
说不同不同,不同在何处呢??
Oraclers 2012-02-13
  • 打赏
  • 举报
回复
Type
TMyInteger = Integer;
這種定義,TMyInteger與Integer是同一個類型,都可以當Integer用。

type
TMyInteger = type Integer;

這個在Integer前加了Type的,TMyInteger與Integer就是不同的類型了。
IHatMyself 2012-02-13
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 oraclers 的回复:]
引用 8 楼 ihatmyself 的回复:
引用 7 楼 delphixxoo 的回复:
楼上那么多人也没扯到重点。
先搞清楚 UTF8String = type string; 和 UTF8String = string;的区别吧。

说说呢 啥区别?


Type identity is almost straightforward. When one type identi……
[/Quote]
那不一样在哪里呢?怎么个不一样法?
Oraclers 2012-02-13
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 ihatmyself 的回复:]
引用 7 楼 delphixxoo 的回复:
楼上那么多人也没扯到重点。
先搞清楚 UTF8String = type string; 和 UTF8String = string;的区别吧。

说说呢 啥区别?
[/Quote]

Type identity is almost straightforward. When one type identifier is declared using another type identifier, without qualification, they denote the same type. Thus, given the declarations

type
T1 = Integer;
T2 = T1;
T3 = Integer;
T4 = T2;

T1, T2, T3, T4, and Integer all denote the same type. To create distinct types, repeat the word type in the declaration. For example,

type TMyInteger = type Integer;

creates a new type called TMyInteger which is not identical to Integer.
IHatMyself 2012-02-13
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 delphixxoo 的回复:]
楼上那么多人也没扯到重点。
先搞清楚 UTF8String = type string; 和 UTF8String = string;的区别吧。
[/Quote]
说说呢 啥区别?
delphixxoo 2012-02-13
  • 打赏
  • 举报
回复
楼上那么多人也没扯到重点。
先搞清楚 UTF8String = type string; 和 UTF8String = string;的区别吧。

lzg827 2012-02-13
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 lzg827 的回复:]
好神奇,我下的SQLLite的pas文件里面没有UTF8String
[/Quote]
另外我发现SQLLite不支持含中文的路径

16,748

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧