如何修改了一项功能,它会返回一个字符串数组数组、它会、字符串、功能

2023-09-04 23:42:09 作者:毕业季,加油!

你能帮助我与此功能

function TdmPush.GetDeviceRegistrationId: string;
begin
{$IFDEF ANDROID}
result := gcmn.RegistrationID;
{$ELSE}
result := 'Mobile Test';
{$ENDIF}
 end;


 function TdmPush.PushMessage(Pushmessage : string):string;
  const
  sendUrl = 'https://android.googleapis.com/gcm/send';
  var
   Params: TStringList;
   AuthHeader: STring;
   idHTTP: TIDHTTP;
   SSLIOHandler: TIdSSLIOHandlerSocketOpenSSL;
   begin
   idHTTP := TIDHTTP.Create(nil);
   try
   SslIOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
   idHTTP.IOHandler := SSLIOHandler;
   idHTTP.HTTPOptions := [];
   Params := TStringList.Create;
    try
     Params.Add('registration_id='+ GetDeviceRegistrationId());
     Params.Values['data.message'] := Pushmessage;
     idHTTP.Request.Host := sendUrl;
     AuthHeader := 'Authorization: key=' + YOUR_API_ID;
      idHTTP.Request.CustomHeaders.Add(AuthHeader);
      IdHTTP.Request.ContentType := 'application/x-www-form-   urlencoded;charset=UTF-8';
     result := idHTTP.Post(sendUrl, Params);
      finally
      Params.Free;
   end;
  finally
    FreeAndNil(idHTTP);
 end;

 end;

我需要的功能 GetDeviceRegeistrationID 返回注册ID的数组,这样我就可以修改Push方法。

I need the function GetDeviceRegeistrationID to return an array of registration id, so I can modify the Push method.

推荐答案

这是例子如何从一个的TListView的项目文本分配到字符串数组。

An example how to assign the text from the items of a TListView into an array of string.

function TdmPush.GetDeviceRegistrationId: TArray<string>;
var
  i: Integer;
begin
  SetLength(Result, myListView.Items.Count);
  ... 
  // Fill the array
  for i := 0 to myListView.Items.Count-1 do
    Result[i] := myListView.Items[i].Text;
end;