我是使用EnumFInQueue获取文件夹下的所有文件,将路径保存到本地数据库中,需要的时候在读取路径,使用ShellExecute执行打开,(Delphi7),现在获取文件名的时候就出现了文件名问号的问题。 procedure EnumFInQueue(path: PChar; FExt: string; var FList: TStringList); var searchRec: TSearchRec; found: Integer; tmpStr: string; curDir: string; dirs: TQueue; //Contnrs pszDir: PChar; begin dirs := TQueue.Create; //创建目录队列 dirs.Push(path); //将起始搜索路径入队 pszDir := dirs.Pop; curDir := StrPas(pszDir); //出 while (True) do begin tmpStr := curDir + '\*.*'; found := FindFirst(tmpStr, faAnyFile, searchRec);//在当前目录查找第一个文件、子目录 while found = 0 do //找到了一个文件或目录后 begin if (FExt='') then begin if ((searchRec.Attr and faDirectory) <> 0) then if (searchRec.Name <> '.') and (searchRec.Name <> '..') then begin FList.Add(searchRec.Name) end; end else begin if ((searchRec.Attr and faDirectory) = 0) then if FExt = '.*' then FList.Add(searchRec.Name) else begin if SameText(RightStr(curDir + '\' + searchRec.Name, Length(FExt)), FExt) then //StrUtils FList.Add( ChangeFileExt(ExtractFileName(searchRec.Name),'')); end; end; found := FindNext(searchRec); end; if dirs.Count > 0 then begin pszDir := dirs.Pop; curDir := StrPas(pszDir); StrDispose(pszDir); end else break; end; dirs.Free; FindClose(searchRec); end;
----------------------------------------------
只会简单使用,并未精通深入
LFileName : string; LMyInvalidChars: TArray<char>; begin LFileName := 'hello|world?.~\txt'; // ExtractFileName(xxxx) -- just name!!! // // TPath.GetInvalidPathChars --> ExtractFileDir(xxxx) -- just path!!! LMyInvalidChars := TPath.GetInvalidFileNameChars + ['~', '[', ']']; // for var i: integer := 1 to LFileName.Length do for var C in LMyInvalidChars do if (LFileName[i] = C) then LFileName[i] := 'X'; // ShowMessage(LFileName);
"I need to write a program which will browse through strings of various lengths and select only those which are written using symbols from set defined by me (particularly Japanese letters). Strings will contain words written in different languages (German, French, Arabic, Russian, English etc). Obviously there is huge number of possible characters. I do not know which structure to use for that? I am using Delphi 7 right now. Can anybody suggest how to write such program? " https://stackoverflow.com/questions/2281223/working-with-unicode-strings-in-delphi-7
12
Obviously you would be better off with Delphi 2010, since the VCL in delphi 7 is not aware of Unicode strings. You can use WideString types, and WideChar types in Delphi 7, and you can install a component set like the TNT Unicode Components to help you create a user interface that can display your results.
For a very-large-set type, consider using a bit array like TBits. A bit array of length 65536 would hold enough to contain every UTF-16 code-point. Checking if Char X is in Set Y, would be basically:
function WideCharsInSet( wcstr:WideString; wcset:TBits):Boolean; var n:Integer; wc:WideChar; begin result := false; for n := 1 to Length(wcstr) do begin wc := wcstr[n]; if wcset[Ord(wc)] then result := true; end; end;
procedure Demo; var wcset1:TBits; s:WideString; begin wcset1 := TBits.Create; try // 1157 - Hangul Korean codepoint I found with Char Map wcset1[1157] := true; // go get a string value s: s := WideChar(1157); // return true if at least one element in set wcset is found in string s: if WideCharsInSet(s,wcset1) then begin Application.MessageBox('Found it','found it',MB_OK); end;
finally wcset1.Free; end;
end;
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
If your Database can define the "CHARSET" for a field, you can store it in a Field with Charset: NONE or OCTETS
Charset in a Database creation of table-fields in Firebird:
NONE: Plain octets, no character set applied. With this character set setting, Firebird is unable to perform conversion operations like UPPER() correctly on anything other than the standard 26 latin letters.
OCTETS: Same as NONE. Cannot be used as client connection character set. Space character is #x00
Ex. Firebird
CREATE TABLE MYTABLE ( ID INTEGER NOT NULL, ... MYFIELD_CHARSET_NONE VARCHAR(200) CHARACTER SET NONE NOT NULL );
None character convertion is done in "MYFIELD_CHARSET_NONE" field! it's stored some like a "byte" (not a specific chars for a specific charset)
NOTE: in Firebird, DIALECT 3 is used for all user-databases. But, DIALECT 2 is used internally in low-level to convertions between DIALECT 1 and 3. DIALECT 2 used OCTECTS!
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3