小编boj*_*vic的帖子

将Python转换为Delphi代码

下一个python代码

from urllib.request import Request, urlopen
import urllib
import json

#ID access to API
TOKEN = "{YOUR_API_TOKEN}" # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
url = "https://cloudpanel-api.1and1.com/v1"

def _setStatusServer(id, content):
  #Configure the request
  _command = url + "/servers/" + id + "/status/action"
  _method = 'PUT'
  request = Request(_command, data=content.encode(encoding='utf_8'), 
                    headers={'X-TOKEN':TOKEN, 'content-
                    type':'application/json'}, 
                    method=_method)

   #Try to get the response
   try:
     response = urlopen(request)
     content = response.read()
     return (content.decode())
  #Fetch error
  except urllib.error.URLError as e:
      return("Error " + str(e.code) + ":" + e.reason) 

  #PARAMETERS
  id = …
Run Code Online (Sandbox Code Playgroud)

python delphi http indy

6
推荐指数
1
解决办法
1078
查看次数

C到delphi的转换

有人可以告诉我在转换中我犯了什么错误:

C:

typedef struct _REGISTRY_EVENT {
    REG_NOTIFY_CLASS eventType;
    TIME_FIELDS time;
    HANDLE processId;
    ULONG dataType;
    ULONG dataLengthB;
    ULONG registryPathLengthB;
    /* Contains path and optionally data */
    UCHAR registryData[];
} REGISTRY_EVENT, * PREGISTRY_EVENT;
Run Code Online (Sandbox Code Playgroud)

德尔福:

_Registry_Event = record
    EventType: REG_NOTIFY_CLASS;
    Time: TIME_FIELDS;
    processID: THandle;
    DataType: ULONG;
    DataLength: ULONG;
    registryPathLength: ULONG;
    registryData: array of UCHAR;
end;
Run Code Online (Sandbox Code Playgroud)

来自c代码sizeof(REGISTRY_EVENT)= 36

来自delphi代码sizeof(REGISTRY_EVENT)= 40

提前致谢

博扬

c windows delphi

1
推荐指数
1
解决办法
504
查看次数

SPI_SETDISABLEOVERLAPPEDCONTENT

我有功能

function bgSetDisableOverlappedContent(CAA: BOOL; var ErrorCode: DWORD; ErrorText: string): Boolean;  
begin
  errorCode := ERROR_SUCCESS;
  ErrorText := '';  
  if not GetOSVersion >= 60 then
    Exit;
  Result := SystemParametersInfo(SPI_SETDISABLEOVERLAPPEDCONTENT, 0, @CAA, 0);
  if not Result then
  begin
    ErrorCode := GetLastError;
    ErrorText := GetErrorText(ErrorCode);
  end;
end;
Run Code Online (Sandbox Code Playgroud)

并准确地称呼它

procedure TForm1.Button3Click(Sender: TObject);
var
  CAA: BOOL;
  OS: TUsableInOS;
  ErrorCode: DWORD;
  ErrorText: string;
begin
  CAA := False;
  if bgSetDisableOverlappedContent(CAA, ErrorCode, ErrorText) then
    ShowMessage('Success');
end;
Run Code Online (Sandbox Code Playgroud)

但是,当我再次检查下一个代码时

function bgGetDisableOverlappedContent(var CAA: BOOL; OS: TUsableInOS; ErrorCode: DWORD; ErrorText: string): Boolean;
begin …
Run Code Online (Sandbox Code Playgroud)

windows delphi winapi

1
推荐指数
1
解决办法
191
查看次数

C到Pascal类型转换

美好的一天,

我在Master(Raspberry pi 2B,使用Lazarus)和Slave - Arduino Nano之间进行I2C通信.在Arduino我定义了

 typedef union
 {
   float Temperature;
   uint8_t bytes[4];
 } floatuint;
 floatuint fu;
Run Code Online (Sandbox Code Playgroud)

我已经定义了覆盆子pi

 TFloatUint = packed record
   case Boolean of
     False: (dabDouble: Double);
     True: (dabByte: packed array[0..3] of cuint8);
 end;
Run Code Online (Sandbox Code Playgroud)

使用命令

 count := FpRead(I2DeviceHandle, fl.dabByte, 4);
Run Code Online (Sandbox Code Playgroud)

我收到字节数组的相同值,但fl.dabDouble显示不同的结果.

例如:

 fu.Temperature = 19.19;
 fu.bytes = (0, 128, 153, 65);

 fl.dabByte = (0, 128, 153, 65);
 fl.dabDouble = 2.6656892163191751e-314
Run Code Online (Sandbox Code Playgroud)

我犯了哪个错误?

c freepascal arduino raspberry-pi

0
推荐指数
2
解决办法
168
查看次数

SetLocaleInfo失败

我有功能

procedure bgGetKeyboardLayoutList(List: TStrings);
var
  AList : array [0..50] of Hkl;
  AklName: array [0..255] of Char;
  i: Longint;
begin
  List.Clear;
  for i := 0 to GetKeyboardLayoutList(SizeOf(AList), AList) - 1 do
    begin
      GetLocaleInfo(LoWord(AList[i]), LOCALE_SLANGUAGE, AklName, SizeOf(
               AklName));
      List.AddObject(AklName, Pointer(AList[i]));
    end;
end;
Run Code Online (Sandbox Code Playgroud)

该函数被调用

procedure TDefaultInputMethod.Scan;
begin
  bgGetKeyboardLayoutList(FSL);
end;
Run Code Online (Sandbox Code Playgroud)

但是当我尝试相反的方向使用SetLocaleInfo时,我没有成功的代码:

procedure TDefaultInputMethod.SetAsDefault(index: integer);
begin
  ActivateKeyboardLayout(Hkl(FSL.Objects[index]), 0); //this line works
  if SetLocaleInfo(LoWord(FSL.Objects[index]), LOCALE_SLANGUAGE, PChar(FSL[index]))  then
     ShowMessage('Uspeh')
  else
    begin
      ShowMessage(IntToStr(GetLastError));
    end;
end;
Run Code Online (Sandbox Code Playgroud)

GetLasrError返回1004

在此先感谢Bojan

delphi winapi

-2
推荐指数
1
解决办法
1114
查看次数

标签 统计

delphi ×4

c ×2

winapi ×2

windows ×2

arduino ×1

freepascal ×1

http ×1

indy ×1

python ×1

raspberry-pi ×1