此代码应该在Delphi XE2中工作,但它在StrtoDateTime转换中给出"不是有效的日期和时间"错误:
procedure TForm2.Button1Click(Sender: TObject);
var
s: string;
d: TDateTime;
FmtStngs: TFormatSettings;
begin
GetLocaleFormatSettings(GetThreadLocale, FmtStngs);
FmtStngs.DateSeparator := #32;
FmtStngs.ShortDateFormat := 'dd mmm yyyy';
FmtStngs.TimeSeparator := ':';
FmtStngs.LongTimeFormat := 'hh:nn';
s := FormatDateTime('', Now, FmtStngs);
d := StrToDateTime(s, FmtStngs);
end;
Run Code Online (Sandbox Code Playgroud)
任何提示?
我正在向条带 API 发送一个带有 Indy http 组件的 JSON,但它没有被 API 接收,因为它是在我收到“错误请求”响应时接收的:
jsnObj := TJSONObject.Create;
jsnObj.AddPair('amount', TJSONNumber.Create('111'));
jsnObj.AddPair('currency', 'eur');
jsnObj.AddPair('customer', 'cus_JNxQsqf6BoK8Rt');
jsnObj.AddPair('description', 'My First Test');
ss := TStringStream.Create(jsnObj.ToString, TEncoding.UTF8);
rs := TStringStream.Create;
IdHTTP1.Request.BasicAuthentication := True;
IdHTTP1.Request.Username := ApiKey ; // test private key
IdHTTP1.Post('https://api.stripe.com/v1/charges', ss, rs);
StatusBar1.SimpleText := IdHTTP1.ResponseText;
Run Code Online (Sandbox Code Playgroud)
要发送的 JSON 是:
{
"amount": 111,
"currency": "eur",
"customer": "cus_JNxQsqf6BoK8Rt",
"description": "My First Test"
}
Run Code Online (Sandbox Code Playgroud)
API 仪表板报告已收到此信息:
{
"{"amount":111,"currency":"eur","customer":"cus_JNxQsqf6BoK8Rt","description":"My First Test"}": null
}
Run Code Online (Sandbox Code Playgroud)
HTTP 组件应该做一些事情,以便以这种方式发送它,包括一个空值,也许是因为在请求中包含了用户名?对于其他 API,相同的 HTTP 组件总是发送它要发送的内容。Stripe 支持表明问题出在我这边。条带文档指定了这一点:
curl -X POST https://api.stripe.com/v1/charges \ …Run Code Online (Sandbox Code Playgroud) 我需要Delphi中的算法来为指定的整数值生成分区.
示例:对于13,如果将5指定为分区的最大值,则它将给出5,5,3; 如果将4指定为最大分区值,则结果应为4,4,4,1,依此类推.
我希望在用户调整大小时按比例调整表单大小.我在事件中OnCanResize使用以下代码完成了此操作:
NewHeight := Round(Height / Width* NewWidth);
Run Code Online (Sandbox Code Playgroud)
为了防止用户通过单击最大化按钮来最大化表单,我设法禁用它WMSysCommand使用以下代码处理消息:
if (AMsg.CmdType = SC_MAXIMIZE) then MessageBeep(0);
Run Code Online (Sandbox Code Playgroud)
我没有设法做的是当用户双击标题栏时阻止最大化表单.在Delphi中有什么办法吗?
我希望很明显,我不想阻止用户调整表单大小.我只是想在单击最大化按钮并双击标题栏时阻止调整大小.
我有以下代码:
user_s.username := EnDecrypt(Edit_username.Text);
Run Code Online (Sandbox Code Playgroud)
功能如下:
function EnDeCrypt(const Value : String) : String;
var
CharIndex : integer;
begin
Result := Value;
for CharIndex := 1 to Length(Value) do
Result[CharIndex] := chr(not(ord(Value[CharIndex])));
end;
Run Code Online (Sandbox Code Playgroud)
变量的类型是:
TUser = record
access: char;
username: string[25];
password: string[25];
end;
Run Code Online (Sandbox Code Playgroud)
在Delphi 2007中它可以工作,在Delphi XE2中它失败了.奇怪的是,如果它是123456789,它会很好地加密/解密密码.这个问题必须与unicode和shortstring的使用有关.我希望有一些方法可以让它在Delphi XE2中运行..