| 1 | unit USimpleChat;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
|---|
| 7 | Dialogs, SunriseChatCoreUnit, SunriseChatNetworkCoreUnit, StdCtrls;
|
|---|
| 8 |
|
|---|
| 9 | type
|
|---|
| 10 | TForm2 = class(TForm)
|
|---|
| 11 | Memo1: TMemo;
|
|---|
| 12 | ListBox1: TListBox;
|
|---|
| 13 | Button1: TButton;
|
|---|
| 14 | Edit1: TEdit;
|
|---|
| 15 | Edit2: TEdit;
|
|---|
| 16 | SunriseChatNetworkCore1: TSunriseChatNetworkCore;
|
|---|
| 17 | procedure FormCreate(Sender: TObject);
|
|---|
| 18 | procedure Button1Click(Sender: TObject);
|
|---|
| 19 | procedure SunriseChatNetworkCore1UserListUpdate;
|
|---|
| 20 | procedure Edit1KeyPress(Sender: TObject; var Key: Char);
|
|---|
| 21 | procedure Edit2Exit(Sender: TObject);
|
|---|
| 22 | procedure SunriseChatNetworkCore1AddMessage(EventType: TAppEventType;
|
|---|
| 23 | Room: TRoom; const Args: array of TVarRec; RoomLine: TRoomLine);
|
|---|
| 24 | procedure ListBox1Click(Sender: TObject);
|
|---|
| 25 | private
|
|---|
| 26 | { Private declarations }
|
|---|
| 27 | public
|
|---|
| 28 | ListBox1LastItemIndex: Integer;
|
|---|
| 29 | end;
|
|---|
| 30 |
|
|---|
| 31 | var
|
|---|
| 32 | Form2: TForm2;
|
|---|
| 33 |
|
|---|
| 34 | implementation
|
|---|
| 35 |
|
|---|
| 36 | uses DateUtils;
|
|---|
| 37 |
|
|---|
| 38 | {$R *.dfm}
|
|---|
| 39 |
|
|---|
| 40 | procedure TForm2.FormCreate(Sender: TObject);
|
|---|
| 41 | var
|
|---|
| 42 | I: Integer;
|
|---|
| 43 | begin
|
|---|
| 44 | with SunriseChatNetworkCore1 do begin
|
|---|
| 45 | BroadcastType := btGlobal;
|
|---|
| 46 | LocalUser.Nick := Edit2.Text;
|
|---|
| 47 | //for I := 0 to NetworkInterfaces.Count-1 do
|
|---|
| 48 | // Memo1.Lines.Add(TNetworkInterface(NetworkInterfaces[I]).IPAddress);
|
|---|
| 49 | TNetworkInterface(NetworkInterfaces[3]).Select;
|
|---|
| 50 | Memo1.Lines.Add('Network interface: '+ActiveNetworkInterface.IPAddress);
|
|---|
| 51 | Active := True;
|
|---|
| 52 | end;
|
|---|
| 53 | end;
|
|---|
| 54 |
|
|---|
| 55 | procedure TForm2.Button1Click(Sender: TObject);
|
|---|
| 56 | begin
|
|---|
| 57 | with SunriseChatNetworkCore1, ListBox1, Items do
|
|---|
| 58 | if (ItemIndex >= 0) and (ItemIndex < Count) then
|
|---|
| 59 | with TUser(UserList[ListBox1.ItemIndex]) do
|
|---|
| 60 | SendCommand(scMessage, Edit1.Text, Id.Machine, Id.User)
|
|---|
| 61 | else SendCommand(scMessage, Edit1.Text);
|
|---|
| 62 | Edit1.Text := '';
|
|---|
| 63 | end;
|
|---|
| 64 |
|
|---|
| 65 | procedure TForm2.SunriseChatNetworkCore1UserListUpdate;
|
|---|
| 66 | var
|
|---|
| 67 | I: Integer;
|
|---|
| 68 | LastItemIndex: Integer;
|
|---|
| 69 | begin
|
|---|
| 70 | with SunriseChatNetworkCore1, ListBox1, Items do begin
|
|---|
| 71 | BeginUpdate;
|
|---|
| 72 | LastItemIndex := ItemIndex;
|
|---|
| 73 | Clear;
|
|---|
| 74 | for I := 0 to UserList.Count-1 do Add(TUser(UserList[I]).Nick);
|
|---|
| 75 | if (LastItemIndex < Count) and (LastItemIndex >= 0) then ItemIndex := LastItemIndex;
|
|---|
| 76 | EndUpdate;
|
|---|
| 77 | end;
|
|---|
| 78 | end;
|
|---|
| 79 |
|
|---|
| 80 | procedure TForm2.Edit1KeyPress(Sender: TObject; var Key: Char);
|
|---|
| 81 | begin
|
|---|
| 82 | if Key = #13 then Button1.OnClick(Self);
|
|---|
| 83 | end;
|
|---|
| 84 |
|
|---|
| 85 | procedure TForm2.Edit2Exit(Sender: TObject);
|
|---|
| 86 | begin
|
|---|
| 87 | SunriseChatNetworkCore1.LocalUser.Nick := Edit2.Text;
|
|---|
| 88 | SunriseChatNetworkCore1.SendCommand(scUserInfo);
|
|---|
| 89 | end;
|
|---|
| 90 |
|
|---|
| 91 | procedure TForm2.SunriseChatNetworkCore1AddMessage(
|
|---|
| 92 | EventType: TAppEventType; Room: TRoom; const Args: array of const;
|
|---|
| 93 | RoomLine: TRoomLine);
|
|---|
| 94 | begin
|
|---|
| 95 | Memo1.Lines.Add(RoomLine.Text);
|
|---|
| 96 | end;
|
|---|
| 97 |
|
|---|
| 98 | procedure TForm2.ListBox1Click(Sender: TObject);
|
|---|
| 99 | begin
|
|---|
| 100 | with ListBox1, Items do begin
|
|---|
| 101 | if (ListBox1LastItemIndex = -1) then begin
|
|---|
| 102 | ListBox1LastItemIndex := ItemIndex;
|
|---|
| 103 | ItemIndex := -1;
|
|---|
| 104 | end else begin
|
|---|
| 105 | ListBox1LastItemIndex := -1
|
|---|
| 106 | end;
|
|---|
| 107 | end;
|
|---|
| 108 | end;
|
|---|
| 109 |
|
|---|
| 110 | end.
|
|---|