我试图从我的Delphi代码使用命令行实用程序(它与dos命令行中的测试一起使用)将PDF转储到文本.
这是我的代码
if fileexists(ExtractFilePath(Application.ExeName) + 'pdftotext.exe') then
begin
ShellExecute(H,'open', 'pdftotext.exe', PWideChar(fFileName), nil, SW_SHOWNORMAL);
if fileExists(changeFileExt(fFileName, '.txt')) then
Lines.LoadFromFile(changeFileExt(fFileName, '.txt'))
else
ShowMessage('File Not found');
end;
Run Code Online (Sandbox Code Playgroud)
在代码中放置断点并单步执行时,它会使用它
if fileExists(changeFileExt(fFileName, '.txt')) then
Run Code Online (Sandbox Code Playgroud)
但是返回false,因此调用了Shellexecute,但是没有转储任何文件
我做错了什么?
这只是一个非常简单的问题,我无法找到一个明确的答案.我没有时间阅读所有文档,因为我正处于紧张状态.
但在这里.
我在我的TForm类之上创建了一个新类,如下所示:
Bucket = Class
glass: Integer;
steel: Integer;
End;
Run Code Online (Sandbox Code Playgroud)
然后我在一个属于TForm1的方法中创建了几个对象
procedure TForm1.getMarbles;
var
objPlastic: Bucket;
objAlu: Bucket;
begin
// Initialize objects
objPlastic := Bucket.Create;
objAlu := Bucket.Create;
// Get Values from edtBox
val(Edit1.Text, objPlastic.steel, code);
val(Edit2.Text, objAlu.steel, code);
val(Edit3.Text, objPlastic.glass, code);
val(Edit4.Text, objAlu.glass, code);
end;
Run Code Online (Sandbox Code Playgroud)
我的问题是我不知道如何在其他方法中使用这些对象.到目前为止,我尝试用我想要使用的其他方法中的各种方式来定义它们,但是我无法让它工作.
这是方法和我当前设置的方法(它始终返回0):
procedure TForm1.marbleDrop(kind: string);
var
objPlastic: Bucket;
I: Integer;
begin
objPlastic := Bucket.Create;
if kind= 'plastic' then // the function is receiving this parameter
begin
for I := 0 to objPlastic.glass do …Run Code Online (Sandbox Code Playgroud) 如何在下载之前检查JPG url是否存在,以避免异常?
procedure TForm1.Button1Click(Sender: TObject);
var
FS: TFileStream;
Url, FileName: String;
I, C: Integer;
begin
for I := 1 to 1000 do
begin
Url := 'http://www.mysite.com/images/' + IntToSTr(I) + '/Image.jpg';
FileName := 'C:\Images\' + IntToStr(I) + '.jpg';
FS := TFileStream.Create(FileName, fmCreate);
try
try
IdHTTP1.Get(Url);
c := IdHTTP1.ResponseCode;
if C = 200 then
IdHTTP1.Get(Url, FS);
except
end;
Application.ProcessMessages;
finally
Fs.Free;
end;
end;
end;
Run Code Online (Sandbox Code Playgroud) 我需要Delphi 2010的工作功能来检查是否有可用的Internet连接.
我说工作是因为到目前为止我尝试了4种不同的方法,例如http://delphi.about.com/b/2005/04/22/how-to-check-for-internet-connection-using-delphi-code.htm但是既没有奏效.
例如,一种方法总是回复说即使电缆不在电脑中也有互联网连接,另一种方法相反(它总是说没有连接).
procedure TForm1.Button1Click(Sender: TObject) ;
function FuncAvail(_dllname, _funcname: string;
var _p: pointer): boolean;
{return True if _funcname exists in _dllname}
var _lib: tHandle;
begin
Result := false;
if LoadLibrary(PChar(_dllname)) = 0 then exit;
_lib := GetModuleHandle(PChar(_dllname)) ;
if _lib <> 0 then begin
_p := GetProcAddress(_lib, PChar(_funcname)) ;
if _p <> NIL then Result := true;
end;
end;
{
Call SHELL32.DLL for Win < Win98
otherwise call URL.dll
}
{button code:}
var
InetIsOffline : function(dwFlags: …Run Code Online (Sandbox Code Playgroud) 我正在使用Delphi 2010并且有一个问题是重新释放对象.
假设我有如下代码,如果发生异常,我想清除TProduct和TPart.
如何释放正确包含的对象TPart?
//Clases are defined like this
TProduct = class(TRemotable)
private
FName: String;
FAge: Integer;
FColor: String;
FPart: TPart;
published
property Name: String read FName write FName;
property Age: Integer read FAge write FAge;
property Color: String read FString write FString;
property Part: TPart read FPart write FPart;
end;
TPart = class(TRemotable)
private
FName: String;
FColor: String;
published
property Name: String read FName write FName;
property Color: String read FString write FString;
end;
//Then in a method, code …Run Code Online (Sandbox Code Playgroud)