我的deplhi应用程序(IE)中集成了一个浏览器.我需要调用某个Web应用程序,我需要在标题中为来自我的应用程序浏览器的所有请求添加一个新变量,例如jquery添加到xhrobj HTTP_X_REQUESTED_WITH
参数.我怎么能这样做呢?代码样本会很棒.我是用的TWebBrowser
.
我有一个注册表项,例如,LocalizedString=@%programfiles%\Internet Explorer\iexplore.exe,-702
是否有一个已知的API来提取路径和字符串而不是自定义解析它(并使用LoadString
)?
然后我有一个defult值,例如(default)="%programfiles%\Internet Explorer\iexplore.exe"
(包括双引号,但没有@
);
Windows如何处理这些东西?
嗨,我有一个带有AdoTable数据集的DBGrid,我的列标题包括"作业ID","旅行ID"和"旅行费用".我希望能够将"旅行费用"值相加,以创建旅行费用总额.我还有以下代码,用于过滤搜索作业ID时成功显示的旅行ID,
DBTravel.DataSource.DataSet.DisableControls;
DBTravel.DataSource.DataSet.Filtered := False;
DBTravel.DataSource.DataSet.Filter := 'Job_ID = ' + edtSearchJobID.Text;
DBTravel.DataSource.DataSet.Filtered := True;
DBTravel.DataSource.DataSet.First;
DBTravel.DataSource.DataSet.EnableControls;
Run Code Online (Sandbox Code Playgroud)
每个工作都有很多旅行费用,因此每个工作ID都有许多旅行ID和旅行费用,最终我希望旅行费用总额只是通过过滤器显示的"旅行费用"值的加法,即旅行费用总和仅包括"旅行费用",其作业ID等于edtSearchJobID.Text,并在搜索后显示在dbgrid中.谢谢
void A() {
B();
// return; <- compiler error "unreachable code"
if (true) return; // <- this works
// code that I will test later
...
C();
D();
}
Run Code Online (Sandbox Code Playgroud)
这就是我现在所做的.是否有一个简单的" exit;
"或" return;
","unreachable code"
如果不使用if
?
只是为了说清楚:if (true) return;
工作(警告"死代码",我不关心,可以抑制)!
如果我只是使用return;
然后我得到"unreachable code"
错误.
注意:一个简单的"不能不使用if
"也是一个可接受的答案,提供参考.
前几天我进行了一次讨论:https://stackoverflow.com/a/42156860/937125
我不太明白为什么一个Abort
比Exit
在这种情况下打电话更好.我倾向于不在我的代码流中使用它.我认为这是一个不好的做法,对代码流程也不好.但@David在评论中的陈述让我想知道我是否遗漏了一些东西:
如果没有静默异常,在深层调用堆栈时如何中止操作.例如,如何使用10深度调用堆栈中止文件复制操作?这不是为什么例外设计的?当然,您可以无异常地对其进行编码,但它更加冗长且容易出错.
我无法想象这种情况.有人能给我一个这样的代码/场景的例子,并说服我Abort
在上面的例子中确实是一件好事并且"更加冗长和容易出错".(3-4深度调用堆栈足以说明)
这是我的代码:
function GetProcedureAddress(var P: FARPROC; const ModuleName, ProcName: AnsiString): Boolean;
var
ModuleHandle: HMODULE;
begin
Result := False;
ModuleHandle := GetModuleHandle(PAnsiChar(AnsiString(ModuleName)));
if ModuleHandle = 0 then
ModuleHandle := LoadLibrary(PAnsiChar(ModuleName)); // DO WE NEED TO CALL FreeLibrary ?
if ModuleHandle <> 0 then
begin
P := Pointer(GetProcAddress(ModuleHandle, PAnsiChar(ProcName)));
if Assigned(P) then
Result := True;
end;
end;
function PathMakeSystemFolder(Path: AnsiString): Boolean;
var
_PathMakeSystemFolderA: function(pszPath: PAnsiChar): BOOL; stdcall;
begin
Result := False;
if GetProcedureAddress(@_PathMakeSystemFolderA, 'shlwapi.dll', 'PathMakeSystemFolderA') then
Result := _PathMakeSystemFolderA(PChar(Path));
end;
Run Code Online (Sandbox Code Playgroud)
如果使用LoadLibrary,我们需要调用FreeLibrary吗?或者当我的申请终止时,它的引用计数会自动递减?
我试图从"Androidapi.JNI.App.pas"(TJservice)扩展一个类/接口,我需要扩展这个类来进行服务.可能吗?怎么样?
我需要重写方法,如:oncreate,onbind,ondestroy.但我不知道怎么做.
我试过这样的事情:
type Tandroidservice= class(TJService)
function onBind(intent: JIntent): JIBinder; override;
procedure onCreate; override;
procedure onDestroy; override;
procedure onStart(intent: JIntent; startId: Integer); override;
end;
Run Code Online (Sandbox Code Playgroud)
有这个错误:
[DCC Error] Unit1.pas(13): E2137 Method 'onBind' not found in base class
[DCC Error] Unit1.pas(14): E2137 Method 'onCreate' not found in base class
[DCC Error] Unit1.pas(15): E2137 Method 'onDestroy' not found in base class
[DCC Error] Unit1.pas(16): E2137 Method 'onStart' not found in base class
[DCC Error] Unit1.pas(13): E2065 Unsatisfied forward or external declaration: 'Tandroidservice.onBind' …
Run Code Online (Sandbox Code Playgroud) 我想知道是否存在异常/错误,这会使您的代码跳转到一个except块但不会被E:exception处理.
try
i := StrToInt(s);
{...do a lot more...}
except
on E : EConvertError do begin
ShowMessage('You need to input a valid number.');
end;
on E : Exception do begin
ShowMessage('Something went wrong.');
Raise;
end;
end;
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以让一个程序错误地忽略这个除了块之外的两个语句?或者我应该这样做:
try
i := StrToInt(s);
{...do a lot more...}
except
on E : EConvertError do begin
ShowMessage('You need to input a valid number.');
end;
else begin // swapped on e : Exception with else
ShowMessage('Something went wrong.');
Raise;
end;
end;
Run Code Online (Sandbox Code Playgroud) 我有以下问题:当我点击网站上的按钮(http://domain-location.com
)时,我收到回复给我的信息,并且网址已更改为http://domain-location.com?key=value
.我想创建一个示例http客户端来轻松接收信息.这是我的代码:
function DoRequest(aVal: string): string;
const DOMAIN = 'http://domain-location.com';
var
request: TIdHTTP;
responseStream: TMemoryStream;
responseLoader: TStringList;
urlRequest: string;
begin
request := TIdHTTP.Create(nil);
responseStream := TMemoryStream.Create;
responseLoader := TStringList.Create;
try
try
// accept ranges didn't help
// request.Response.AcceptRanges := 'text/json';
// request.Response.AcceptRanges := 'text/xml';
urlRequest := DOMAIN + '?key=' + aVal;
request.Get(urlRequest, responseStream);
responseStream.Position := 0;
responseLoader.LoadFromStream(responseStream);
Result := responseLoader.Text;
except on E: Exception do
Result := e.Message;
end;
finally
responseLoader.Free;
responseStream.Free;
request.Free;
end;
end;
Run Code Online (Sandbox Code Playgroud)
编辑在第一个答案后我编辑了我的功能(仍然无法正常工作): …
我有简单的查询,它返回以下行:
Name Value
Peter 1
Peter 2
Peter 3
John 1
John 2
Run Code Online (Sandbox Code Playgroud)
应用过滤器:
ADO.Filter := 'Name="John"';
ADO.Filtered := True; // Now, its only 2 rows in dataset
ADO.Locate('Value', 2);
Run Code Online (Sandbox Code Playgroud)
光标应指向"John 2",但它指向"Peter 2"(由滤镜过滤掉).并且定位返回True.
尝试使用Delphi 7,Rad studio XE 6.看来这个错误是在过去的15年里存在的任何解决方案?
delphi ×8
ado ×2
java ×2
winapi ×2
windows ×2
abort ×1
android ×1
api ×1
class ×1
data-binding ×1
delphi-7 ×1
delphi-xe5 ×1
exception ×1
filter ×1
httpclient ×1
indy10 ×1
locate ×1
return ×1
twebbrowser ×1