How to write SMS content to common VCL visible window?
Submitted by admin on Thu, 2006-04-27 18:56.
Since UnsolicitedSMS event is not called in a VCL thread it is impossible
to write to VCL class. Received SMS is possible write e.g. to
TStringList and by means of auxiliary TTimer class event list its
content to VCL window. Example:
TxxForm = class(TForm) ... GSM: TGSM; Timer1: TTimer; fSMSReceiveQ: TStrings; MemA: TMemo; ... end; procedure TxxForm.UnsolicitedSMS(Sender: TObject; Idx: Integer; aSMS: TSMS); var Stat: Integer; begin if aSMS = nil then { PDU mode } try aSMS:= GSM.ReadSMS(Idx, Stat); fSMSReceived.Add(TMTSMS(aSMS).OA+'/'+aSMS.UD); finally GSM.DeleteSMS(Idx); end else begin { text mode } fSMSReceived.Add(TMTSMS(aSMS).OA+'/'+aSMS.UD); if Idx <> -1 then GSM.DeleteSMS(Idx); end; end; procedure TxxForm.Timer1Timer(Sender: TObject); begin if fSMSReceived.Count > 0 then begin with TCriticalSection.Create do try Enter; try while fSMSReceived.Count>0 do begin Memo.Lines.Add(fSMSReceived[0]); // text do memo fSMSReceived.Delete(0); end; finally Leave; end; finally Free; end; end; end;