OemToAnsiStr()是將什麼轉成字符型? |
答題得分者是:babyfish0226
|
books
一般會員 ![]() ![]() 發表:9 回覆:27 積分:7 註冊:2006-10-27 發送簡訊給我 |
程式編譯時,就出現報錯,錯誤停在OemToAnsiStr處,那麼標題出自於下面語句:
DestTable.Open; try Check(DbiGetDirectory(DestTable.DBHandle, False, TablePath)); Path := NormalDir(OemToAnsiStr(StrPas(TablePath))); finally DestTable.Close; end; 上面這段程式出自於batchmove,詳見如下: procedure ExportDataSetEx(Source: TBDEDataSet; DestTable: TTable; TableType: TTableType; const AsciiCharSet: string; AsciiDelimited: Boolean; AsciiDelimiter, AsciiSeparator: Char; MaxRecordCount: Longint); function ExportAsciiField(Field: TField): Boolean; begin Result := Field.Visible and not (Field.Calculated {$IFDEF WIN32} or Field.Lookup {$ENDIF}) and not (Field.DataType in ftNonTextTypes [ftUnknown]); end; const TextExt = '.TXT'; SchemaExt = '.SCH'; var I: Integer; S, Path: string; BatchMove: TBatchMove; TablePath: array[0..dbiMaxPathLen] of Char; begin if Source = nil then _DBError(SDataSetEmpty); if DestTable.Active then DestTable.Close; {$IFDEF WIN32} if Source is TDBDataSet then DestTable.SessionName := TDBDataSet(Source).SessionName; {$ENDIF} if (TableType = ttDefault) then begin if DestTable.TableType <> ttDefault then TableType := DestTable.TableType else if (CompareText(ExtractFileExt(DestTable.TableName), TextExt) = 0) then TableType := ttASCII; end; BatchMove := TBatchMove.Create(Application); try StartWait; try BatchMove.Mode := batCopy; BatchMove.Source := Source; BatchMove.Destination := DestTable; DestTable.TableType := TableType; BatchMove.Mappings.Clear; if (DestTable.TableType = ttASCII) then begin if CompareText(ExtractFileExt(DestTable.TableName), SchemaExt) = 0 then DestTable.TableName := ChangeFileExt(DestTable.TableName, TextExt); with Source do for I := 0 to FieldCount - 1 do begin if ExportAsciiField(Fields[I]) then BatchMove.Mappings.Add(Format('%s=%0:s', [Fields[I].FieldName])); end; BatchMove.RecordCount := 1; end else BatchMove.RecordCount := MaxRecordCount; BatchMove.Execute; if (DestTable.TableType = ttASCII) then begin { ASCII table always created in "fixed" format with "ascii" character set } with BatchMove do begin Mode := batAppend; RecordCount := MaxRecordCount; end; S := ChangeFileExt(ExtractFileName(DestTable.TableName), ''); Path := NormalDir(ExtractFilePath(DestTable.TableName)); if Path = '' then begin DestTable.Open; try Check(DbiGetDirectory(DestTable.DBHandle, False, TablePath)); Path := NormalDir(OemToAnsiStr(StrPas(TablePath))); finally DestTable.Close; end; end; with TIniFile.Create(ChangeFileExt(Path S, SchemaExt)) do try if AsciiCharSet <> '' then WriteString(S, 'CharSet', AsciiCharSet) else WriteString(S, 'CharSet', 'ascii'); if AsciiDelimited then begin { change ASCII-file format to CSV } WriteString(S, 'Filetype', 'VARYING'); WriteString(S, 'Delimiter', AsciiDelimiter); WriteString(S, 'Separator', AsciiSeparator); end; finally Free; end; { clear previous output - overwrite existing file } S := Path ExtractFileName(DestTable.TableName); if Length(ExtractFileExt(S)) < 2 then S := ChangeFileExt(S, TextExt); I := FileCreate(S); if I < 0 then raise EFCreateError.CreateFmt(ResStr(SFCreateError), [S]); FileClose(I); BatchMove.Execute; end; finally StopWait; end; finally BatchMove.Free; end; end; |
babyfish0226
一般會員 ![]() ![]() 發表:9 回覆:82 積分:23 註冊:2002-06-14 發送簡訊給我 |
網路上找的
OemToAnsiStr - OemToAnsiStr translates a string from the OEM character set into the Windows character set. function OemToAnsiStr(const OemStr: string): string; begin SetLength(Result, Length(OemStr)); if Length(Result) > 0 then OemToCharBuff(PChar(OemStr), PChar(Result), Length(Result)); end; procedure TForm1.Button1Click(Sender: TObject); var LIn, LOut: TStringList; begin LIn := TStringList.Create; LOut := TStringList.Create; try LIn.LoadFromFile('testdos.txt'); LOut.Text := OemToAnsiStr(LIn.Text); LOut.SaveToFile(ExtractFilePath(ParamStr(0)) 'readmewin.txt'); //Memo1.Lines.Assign(LOut); finally LIn.Free; LOut.Free; end; end; |
books
一般會員 ![]() ![]() 發表:9 回覆:27 積分:7 註冊:2006-10-27 發送簡訊給我 |
|
books
一般會員 ![]() ![]() 發表:9 回覆:27 積分:7 註冊:2006-10-27 發送簡訊給我 |
===================引 用 文 章=================== 我搜了很久沒找不到,不好意思,謝謝前輩,另外我還有下面這個: ??????I := FileCreate(S); ????? if I < 0 then ????????? raise EFCreateError.CreateFmt(ResStr(SFCreateError), [S]); ??????? FileClose(I); 如這個紅色的SFCreateError,此又是什麼意思?請前輩們指點迷津! 添加一條這樣語句就行了:SFCreateError = '無法建立文件 %s'; |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |