VCL를 사용하지 않고 Synchronize를 이용해서 아래의 내용을 처리하고자 합니다. 짧은 지식으로 아래 부분을 Synchronize로 처리하려 해도 워낙 초보라 어떻게 해야 할지 ....
고수님들의 조언을 좀 부탁드립니다.
procedure TfrmMain.IdTCPServerExecute(AThread: TIdPeerThread);
var
// Command : String;
FindItem, AddItem: TListItem;
var
CommBlock: TCommBlock;
RetrunStr: String;
begin
if not AThread.Terminated and AThread.Connection.Connected then
begin
AThread.Connection.ReadBuffer(CommBlock, SizeOf (CommBlock));
if (CommBlock.Command = 'Add') then
begin
MemoAdd.Lines.Add(CommBlock.SafemanID+'|'+CommBlock.IDNo);
end else
if (CommBlock.Command = 'Edit') then
begin
MemoAdd.Lines.Add(CommBlock.SafemanID+'|'+CommBlock.IDNo);
end else
if (CommBlock.Command = 'Del') then
begin
MemoDel.Lines.Add(CommBlock.SafemanID+'|'+CommBlock.IDNo);
end else
if (CommBlock.Command = 'LogOut') then
begin
FindItem := ListView.FindCaption(-1, CommBlock.UserID, False, False, False);
if (FindItem <> nil) and (FindItem.SubItems[0] = CommBlock.ComName) then
begin
MsgAdd('LogOut: '+ CommBlock.UserID +'['+AThread.Connection.Socket.Binding.PeerIP+']');
FindItem.Delete;
end;
end else
if (CommBlock.Command = 'LogIn') then
begin
FindItem := ListView.FindCaption(-1, CommBlock.UserID, False, False, False);
if FindItem = nil then
begin
MsgAdd('LogIn: '+ CommBlock.UserID +'['+AThread.Connection.Socket.Binding.PeerIP+']');
RetrunStr := 'LogIn';
ListView.Items.BeginUpdate;
AddItem := ListView.Items.Add;
AddItem.Caption := CommBlock.UserID; // ID
AddITem.SubItems.Add(CommBlock.ComName); // Name
AddITem.SubItems.Add(AThread.Connection.Socket.Binding.PeerIP); // IP
AddITem.SubItems.Add(FormatDateTime('yyyy-mm-dd hh:nn:ss',Now)); // Time
AddITem.SubItems.Add(IntToStr(AThread.Connection.Socket.Binding.Handle));
ListView.Items.EndUpdate;
end else
begin
if (FindItem.Caption = CommBlock.UserID) and
(FindItem.SubItems[0] = CommBlock.ComName) and
(FindItem.SubItems[1] = AThread.Connection.Socket.Binding.PeerIP) then RetrunStr := 'LogIn' else
begin
MsgAdd('Using: '+ CommBlock.UserID +'['+AThread.Connection.Socket.Binding.PeerIP+']');
RetrunStr := 'Using';
end;
end;
CommBlock.Command := RetrunStr;
CommBlock.UserID := '';
CommBlock.SafemanID := '';
CommBlock.IDNo := '';
AThread.Connection.WriteBuffer(CommBlock, SizeOf(CommBlock));
end;
end;
end;