LCDHype Forum

Full Version: Plugin erstellen wie verhindere ich die löschung der Leerzeichen?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hallo,

Ich komme nicht weiter beim erstellen von einem Plugin.


Wie verhindere ich die löschung der Leerzeichen?

Verzeit mir die Frage aber ich kenne Delphi erst ein paar Tagen Smile



Hier ein Code schnipsel für Plugin.DVBViewerMS.GetTimerChannelName:


Code:
// Plugin.DVBViewerMS.GetTimerChannelName
function Library_GetTimerChannelName(const AParameter: PScriptFunctionImplementationParameter): PWideChar; stdcall;
var
 lTimer : PWideChar;
 lScriptFunctionParameter : PScriptFunctionParameter;
begin
 gReturnValue := '';
 if AParameter^.StructureSize >= SizeOf(TScriptFunctionImplementationParameter) then
 begin
   if AParameter^.ParameterCount > 0 then
   begin
     lScriptFunctionParameter := AParameter.ParameterList;
     lTimer := lScriptFunctionParameter^.Value;
     gReturnValue := timersChannelName[StrToInt(lTimer)];
   end;
 end;
 result := PWideChar(gReturnValue);
end;





Hier mal mein komplettes Plugin:


Code:
//
// LCDHype Plugin SDK
//
// $Id: DVBViewerMSex.pas 4 2011-05-14 18:09:04Z LostSoul $
//

unit DVBViewerMSex;

interface

uses
 Windows,
 System.SysUtils,
 System.Classes,
 ScriptEngineInterface,
 IdHTTP,
 xmldom,
 XMLIntf,
 XMLDoc,
 Vcl.Dialogs;

const //ID sets the description of the dll
 ID   = 'DVBViewerMS';

 //if an array elem shows this value it marks the end of data
 EOL  = #0;
 MAX_AREAS = 255;


//TData struct required for plugin
type TData  = record
 data : array[0..65535] of byte;
end;

//pixel informations of gfx output
TVRAMBitmap = array[0..319,0..319] of byte;

//list of refresh areas set by plugin for correct drawing of gfx output
TAreas      = array[0..MAX_AREAS,0..3] of integer;

//configuration information data from lcdhype
TConfigInfo = record
 gLCDx : word; //width of gLCD in pixels
 gLCDy : word; //height of gLCD in pixels
end;


function GetData(parameter : PAnsiChar) : TData; stdcall;
function GetDataEx(parameter : PAnsiChar; var pixels : TVRAMBitmap; var Areas : TAreas; var AreasCount : integer; Config : TConfigInfo) : TData; stdcall;
function GetID : TData; stdcall;

function ConnectToDVBViewerMS(const CHost, CPort, CPath, CUser, CPass : UnicodeString): PWideChar; stdcall;

var
 timersDate : TStringList;
 timersStart : TStringList;
 timersEnd : TStringList;
 timersDescr : TStringList;
 timersChannelName : TStringList;
 timersExecuteable : TStringList;
 timersRecording : TStringList;

 Connection : TScriptFunctionImplementation;
 CountTimers : TScriptFunctionImplementation;
 GetRecordStatus : TScriptFunctionImplementation;
 GetTimerDate : TScriptFunctionImplementation;
 GetTimerStartTime : TScriptFunctionImplementation;
 GetTimerEndTime : TScriptFunctionImplementation;
 GetTimerDescription : TScriptFunctionImplementation;
 GetTimerChannelName : TScriptFunctionImplementation;
 GetTimerExecuteable : TScriptFunctionImplementation;
 GetTimerRecording : TScriptFunctionImplementation;


implementation




{$REGION ' Plugin Helper '}


function ConnectToDVBViewerMS(const CHost, CPort, CPath, CUser, CPass : UnicodeString): PWideChar; stdcall;
var
 IdHTTP: TIdHTTP;
 xmlDoc : IXMLDocument;
 xmlStrem: TMemoryStream;
 i: LongInt;
 gReturnValue: WideString;
begin
 IdHTTP := nil;
 xmlDoc := nil;
 xmlStrem := nil;
 timersDate := TStringList.Create;
 timersStart := TStringList.Create;
 timersEnd := TStringList.Create;
 timersDescr := TStringList.Create;
 timersChannelName := TStringList.Create;
 timersExecuteable := TStringList.Create;
 timersRecording := TStringList.Create;
 try
   try
     IdHTTP := TIdHTTP.Create;
     IdHTTP.HandleRedirects := True;
     IdHTTP.ConnectTimeout := 60000;
     IdHTTP.Request.Clear;
     IdHTTP.Request.BasicAuthentication := true;
     IdHTTP.Request.Username := CUser;
     IdHTTP.Request.Password := CPass;
     xmlStrem := TMemoryStream.Create;
     IdHTTP.Get('http://' + CHost + ':' + CPort + CPath, xmlStrem);
     xmlDoc := newXMLDocument;
     xmlDoc.LoadFromStream(xmlStrem);
     xmldoc.Active := true;
     for i := 0 to xmlDoc.ChildNodes['Timers'].ChildNodes.Count - 1 do
     begin
       timersDate.Add(xmlDoc.DocumentElement.ChildNodes[i].Attributes['Date']);
       timersStart.Add(xmlDoc.DocumentElement.ChildNodes[i].Attributes['Start']);
       timersEnd.Add(xmlDoc.DocumentElement.ChildNodes[i].Attributes['End']);
       timersDescr.Add(xmlDoc.DocumentElement.ChildNodes[i].ChildNodes['Descr'].Text);
       timersChannelName.Add(Copy(xmlDoc.DocumentElement.ChildNodes[i].ChildNodes['Channel'].Attributes['ID'], 21, 255));
       timersExecuteable.Add(IntToStr(abs(StrToInt(xmlDoc.DocumentElement.ChildNodes[i].ChildNodes['Executeable'].Text))));
       timersRecording.Add(IntToStr(abs(StrToInt(xmlDoc.DocumentElement.ChildNodes[i].ChildNodes['Recording'].Text))));
     end;
   except
     on E: Exception do
     begin
       gReturnValue := 'ConnectionError';
     end;
   end;
 finally
   if Assigned(IdHTTP) then FreeAndNil(IdHTTP);
   if Assigned(xmlDoc) then FreeAndNil(xmlDoc);
   if Assigned(xmlStrem) then FreeAndNil(xmlStrem);
 end;
 result := PWideChar(gReturnValue);
end;


{$ENDREGION}




{$REGION ' Plugin interface '}


function GetDataEx(parameter : PAnsiChar; var pixels : TVRAMBitmap; var Areas : TAreas; var areascount : integer; Config : TConfigInfo) : TData; stdcall;
var return : AnsiString;
   c : integer;
   x : TData;
begin
    FillChar(x.data,sizeof(x.data),EOL);
    areas[areascount,0] := 0;
    areas[areascount,1] := 0;
    areas[areascount,2] := 49;
    areas[areascount,3] := 49;
    for c:=0 to 49 do
     pixels[c,c] := 1;
    for c:=0 to length(return)-1 do
     x.data[c] := ord(return[c+1]);
    result := x;
end;

function GetData(parameter : PAnsiChar) : TData;
var return : AnsiString;
   c : integer;
   x : TData;
begin
    FillChar(x.data,sizeof(x.data),EOL);
    return := '';
    return := AnsiString(TimeToStr(time));
    str(gettickcount div 1000,return);
    return := 'Hello World!';
    for c:=0 to length(return)-1 do
     x.data[c] := ord(return[c+1]);
    result := x;
end;

function GetID : TData;
var c : integer; ids : TData;
begin
    for c:=0 to length(ID)-1 do
     ids.data[c] := ord(ID[c+1]);
    for c:=length(ID) to sizeof(ids.data)-1 do
     ids.data[c] := ord(EOL);
    result := ids;
end;


{$ENDREGION}




{$REGION ' Script engine interface '}


var
 gReturnValue: WideString = '';

// Plugin.DVBViewerMS.Connection
function Library_Connection(const AParameter: PScriptFunctionImplementationParameter): PWideChar; stdcall;
var
 lHost, lPort, lPath, lUser, lPass : PWideChar;
 lScriptFunctionParameter : PScriptFunctionParameter;
begin
 gReturnValue := 'True';
 if AParameter^.StructureSize >= SizeOf(TScriptFunctionImplementationParameter) then
 begin
   if AParameter^.ParameterCount >= 3 then
   begin
     lScriptFunctionParameter := AParameter.ParameterList;
     lHost := lScriptFunctionParameter^.Value;
     Inc(lScriptFunctionParameter);
     lPort := lScriptFunctionParameter^.Value;
     Inc(lScriptFunctionParameter);
     lPath := lScriptFunctionParameter^.Value;
     Inc(lScriptFunctionParameter);
     lUser := lScriptFunctionParameter^.Value;
     Inc(lScriptFunctionParameter);
     lPass := lScriptFunctionParameter^.Value;
     ConnectToDVBViewerMS(lHost, lPort, lPath, lUser, lPass);
   end;
 end;
 result := PWideChar(gReturnValue);
end;


// Plugin.DVBViewerMS.CountTimers
function Library_CountTimers(const AParameter: PScriptFunctionImplementationParameter): PWideChar; stdcall;
begin
 result := PWideChar(IntToStr(timersRecording.Count));
end;


// Plugin.DVBViewerMS.GetRecordStatus
function Library_GetRecordStatus(const AParameter: PScriptFunctionImplementationParameter): PWideChar; stdcall;
var
 tr : LongInt;
 i : LongInt;
begin
 tr := 0;
 for i := 0 to timersRecording.Count - 1 do
 begin
   if timersRecording[i] = '1' then
     tr := tr + 1;
 end;
 result := PWideChar(IntToStr(tr));
end;


// Plugin.DVBViewerMS.GetTimerDate
function Library_GetTimerDate(const AParameter: PScriptFunctionImplementationParameter): PWideChar; stdcall;
var
 lTimer : PWideChar;
 lScriptFunctionParameter : PScriptFunctionParameter;
begin
 gReturnValue := '';
 if AParameter^.StructureSize >= SizeOf(TScriptFunctionImplementationParameter) then
 begin
   if AParameter^.ParameterCount > 0 then
   begin
     lScriptFunctionParameter := AParameter.ParameterList;
     lTimer := lScriptFunctionParameter^.Value;
     gReturnValue := timersDate[StrToInt(lTimer)];
   end;
 end;
 result := PWideChar(gReturnValue);
end;


// Plugin.DVBViewerMS.GetTimerStartTime
function Library_GetTimerStartTime(const AParameter: PScriptFunctionImplementationParameter): PWideChar; stdcall;
var
 lTimer : PWideChar;
 lScriptFunctionParameter : PScriptFunctionParameter;
begin
 gReturnValue := '';
 if AParameter^.StructureSize >= SizeOf(TScriptFunctionImplementationParameter) then
 begin
   if AParameter^.ParameterCount > 0 then
   begin
     lScriptFunctionParameter := AParameter.ParameterList;
     lTimer := lScriptFunctionParameter^.Value;
     gReturnValue := timersStart[StrToInt(lTimer)];
   end;
 end;
 result := PWideChar(gReturnValue);
end;


// Plugin.DVBViewerMS.GetTimerEndTime
function Library_GetTimerEndTime(const AParameter: PScriptFunctionImplementationParameter): PWideChar; stdcall;
var
 lTimer : PWideChar;
 lScriptFunctionParameter : PScriptFunctionParameter;
begin
 gReturnValue := '';
 if AParameter^.StructureSize >= SizeOf(TScriptFunctionImplementationParameter) then
 begin
   if AParameter^.ParameterCount > 0 then
   begin
     lScriptFunctionParameter := AParameter.ParameterList;
     lTimer := lScriptFunctionParameter^.Value;
     gReturnValue := timersEnd[StrToInt(lTimer)];
   end;
 end;
 result := PWideChar(gReturnValue);
end;


// Plugin.DVBViewerMS.GetTimerDescription
function Library_GetTimerDescription(const AParameter: PScriptFunctionImplementationParameter): PWideChar; stdcall;
var
 lTimer : PWideChar;
 lScriptFunctionParameter : PScriptFunctionParameter;
begin
 gReturnValue := '';
 if AParameter^.StructureSize >= SizeOf(TScriptFunctionImplementationParameter) then
 begin
   if AParameter^.ParameterCount > 0 then
   begin
     lScriptFunctionParameter := AParameter.ParameterList;
     lTimer := lScriptFunctionParameter^.Value;
     gReturnValue := timersDescr[StrToInt(lTimer)];
   end;
 end;
 result := PWideChar(gReturnValue);
end;


// Plugin.DVBViewerMS.GetTimerChannelName
function Library_GetTimerChannelName(const AParameter: PScriptFunctionImplementationParameter): PWideChar; stdcall;
var
 lTimer : PWideChar;
 lScriptFunctionParameter : PScriptFunctionParameter;
begin
 gReturnValue := '';
 if AParameter^.StructureSize >= SizeOf(TScriptFunctionImplementationParameter) then
 begin
   if AParameter^.ParameterCount > 0 then
   begin
     lScriptFunctionParameter := AParameter.ParameterList;
     lTimer := lScriptFunctionParameter^.Value;
     gReturnValue := timersChannelName[StrToInt(lTimer)];
   end;
 end;
 result := PWideChar(gReturnValue);
end;


// Plugin.DVBViewerMS.GetTimerExecuteable
function Library_GetTimerExecuteable(const AParameter: PScriptFunctionImplementationParameter): PWideChar; stdcall;
var
 lTimer : PWideChar;
 lScriptFunctionParameter : PScriptFunctionParameter;
begin
 gReturnValue := '';
 if AParameter^.StructureSize >= SizeOf(TScriptFunctionImplementationParameter) then
 begin
   if AParameter^.ParameterCount > 0 then
   begin
     lScriptFunctionParameter := AParameter.ParameterList;
     lTimer := lScriptFunctionParameter^.Value;
     gReturnValue := timersExecuteable[StrToInt(lTimer)];
   end;
 end;
 result := PWideChar(gReturnValue);
end;


// Plugin.DVBViewerMS.GetTimerRecording
function Library_GetTimerRecording(const AParameter: PScriptFunctionImplementationParameter): PWideChar; stdcall;
var
 lTimer : PWideChar;
 lScriptFunctionParameter : PScriptFunctionParameter;
begin
 gReturnValue := '';
 if AParameter^.StructureSize >= SizeOf(TScriptFunctionImplementationParameter) then
 begin
   if AParameter^.ParameterCount > 0 then
   begin
     lScriptFunctionParameter := AParameter.ParameterList;
     lTimer := lScriptFunctionParameter^.Value;
     gReturnValue := timersRecording[StrToInt(lTimer)];
   end;
 end;
 result := PWideChar(gReturnValue);
end;


{$ENDREGION}


initialization
 Connection := @Library_Connection;
 GetRecordStatus := @Library_GetRecordStatus;
 CountTimers := @Library_CountTimers;
 GetTimerDate := @Library_GetTimerDate;
 GetTimerStartTime := @Library_GetTimerStartTime;
 GetTimerEndTime := @Library_GetTimerEndTime;
 GetTimerDescription := @Library_GetTimerDescription;
 GetTimerChannelName := @Library_GetTimerChannelName;
 GetTimerExecuteable := @Library_GetTimerExecuteable;
 GetTimerRecording := @Library_GetTimerRecording;
end.
Ha!

Nach ein bisschen überlegen hab ich das mal versucht:
Code:
result := PWideChar(#39 + gReturnValue + #39);

Code:
// Plugin.DVBViewerMS.GetTimerChannelName
function Library_GetTimerChannelName(const AParameter: PScriptFunctionImplementationParameter): PWideChar; stdcall;
var
 lTimer : PWideChar;
 lScriptFunctionParameter : PScriptFunctionParameter;
begin
 gReturnValue := '';
 if AParameter^.StructureSize >= SizeOf(TScriptFunctionImplementationParameter) then
 begin
   if AParameter^.ParameterCount > 0 then
   begin
     lScriptFunctionParameter := AParameter.ParameterList;
     lTimer := lScriptFunctionParameter^.Value;
     gReturnValue := timersChannelName[StrToInt(lTimer)];
   end;
 end;
 result := PWideChar(#39 + gReturnValue + #39);
end;
So gehts! Vermutlich fällt das unter quick and dirty Big Grin