Chat

TsgcHTMLComponent_Chat — una messaggistica in stile WhatsApp con messaggi di testo, immagine, file, audio e video, conferme di lettura, risposte e separatori di data, in Delphi, C++ Builder e .NET.

TsgcHTMLComponent_Chat

Una superficie di chat completa che emette CSS dedicato più il markup della messaggistica: un’intestazione con avatar, bolle raggruppate, spunte di stato, allegati multimediali e un campo di composizione. Aggiungi i messaggi, imposta l’intestazione, quindi leggi la proprietà HTML.

Classe del componente

TsgcHTMLComponent_Chat

Renderizza

Scoped CSS + messenger markup

Famiglia

Chat e IA

Linguaggi

Delphi, C++ Builder, .NET

Crealo, aggiungi i messaggi, renderizzalo

Imposta l’intestazione (Title, Subtitle, HeaderAvatarInitials), aggiungi messaggi di testo, immagine e file, gestisci OnSendMessage, quindi leggi HTML.

uses
  sgcHTML_Enums, sgcHTML_Component_Chat;

var
  oChat: TsgcHTMLComponent_Chat;
begin
  oChat := TsgcHTMLComponent_Chat.Create(nil);
  try
    oChat.Title := 'Alice Johnson';
    oChat.Subtitle := 'online';
    oChat.HeaderAvatarInitials := 'AJ';
    oChat.Height := '500px';
    oChat.ShowTypingIndicator := True;
    oChat.OnSendMessage := DoSendMessage;   // browser -> your code

    oChat.AddSystemMessage('Today');
    oChat.AddMessage('Alice', 'Hey! Did you get the file?', maLeft);
    oChat.AddImageMessage('You', '/img/receipt.png', maRight,
      hcPrimary, 'Here it is');
    oChat.AddFileMessage('You', '/files/report.pdf',
      'report.pdf', '248 KB', maRight);

    WebModule.Response := oChat.HTML;   // messenger markup + scoped CSS
  finally
    oChat.Free;
  end;
end;

// OnSendMessage fires when the visitor submits the composer:
procedure TForm1.DoSendMessage(Sender: TObject; const aMessage: string);
begin
  oChat.AddMessage('You', aMessage, maRight, hcPrimary);
  WebSocket.WriteData(oChat.GetLastMessageHTML);
end;
// includes: sgcHTML_Enums.hpp, sgcHTML_Component_Chat.hpp

TsgcHTMLComponent_Chat *oChat = new TsgcHTMLComponent_Chat(NULL);
try
{
  oChat->Title = "Alice Johnson";
  oChat->Subtitle = "online";
  oChat->HeaderAvatarInitials = "AJ";
  oChat->Height = "500px";
  oChat->ShowTypingIndicator = true;
  oChat->OnSendMessage = DoSendMessage;   // browser -> your code

  oChat->AddSystemMessage("Today");
  oChat->AddMessage("Alice", "Hey! Did you get the file?", maLeft);
  oChat->AddImageMessage("You", "/img/receipt.png", maRight,
    hcPrimary, "Here it is");
  oChat->AddFileMessage("You", "/files/report.pdf",
    "report.pdf", "248 KB", maRight);

  String html = oChat->HTML;   // messenger markup + scoped CSS
}
__finally
{
  delete oChat;
}
using esegece.sgcWebSockets;

var chat = new TsgcHTMLComponent_Chat();
chat.Title = "Alice Johnson";
chat.Subtitle = "online";
chat.HeaderAvatarInitials = "AJ";
chat.Height = "500px";
chat.ShowTypingIndicator = true;
chat.OnSendMessage += (sender, message) =>   // browser -> your code
{
    chat.AddMessage("You", message, TsgcHTMLChatMessageAlign.maRight, TsgcHTMLColor.hcPrimary);
};

chat.AddSystemMessage("Today");
chat.AddMessage("Alice", "Hey! Did you get the file?", TsgcHTMLChatMessageAlign.maLeft);
chat.AddImageMessage("You", "/img/receipt.png", TsgcHTMLChatMessageAlign.maRight,
    TsgcHTMLColor.hcPrimary, "Here it is");
chat.AddFileMessage("You", "/files/report.pdf",
    "report.pdf", "248 KB", TsgcHTMLChatMessageAlign.maRight);

string html = chat.HTML;   // messenger markup + scoped CSS

Proprietà e metodi principali

I membri che utilizzerai più spesso.

Messaggi

Messages è una collezione TsgcHTMLChat_Messages; ogni TsgcHTMLChat_Message porta Text, MessageType (text/image/file/audio/video/system), Status, ReplyToSender/ReplyToText e IsForwarded.

Aggiungere messaggi

AddMessage, AddImageMessage, AddFileMessage e AddSystemMessage(...) aggiungono bolle; maLeft/maRight scelgono il lato.

Intestazione

Title, Subtitle, HeaderAvatarURL e HeaderAvatarInitials costruiscono l’intestazione della conversazione (un sottotitolo "online" aggiunge l’indicatore verde).

Composizione

ShowInput, InputPlaceholder, ShowAttachButton, ShowEmojiButton, ShowTypingIndicator e TypingText regolano la barra inferiore.

Opzioni

Options (un TsgcHTMLChat_Options) imposta MaxBubbleWidth, i colori di bolle/sfondo, ShowTimestamp, ShowStatus, GroupConsecutive e ShowDateSeparators.

Eventi e output

OnSendMessage si attiva quando il visitatore invia dal campo di composizione; OnMediaClick si attiva al tocco di un contenuto multimediale. HTML restituisce la chat; GetLastMessageHTML restituisce solo la bolla più recente per gli aggiornamenti live.

Continua a esplorare

Tutti i componenti sgcHTMLEsplora la matrice completa delle funzionalità di oltre 60 componenti.
Scarica la Prova GratuitaLa prova di 30 giorni include i progetti demo 60.HTML.
PrezziLicenze Single, Team e Site con codice sorgente completo.

Pronto a Iniziare?

Scarica la versione di prova gratuita e inizia a creare interfacce web in Delphi, C++ Builder e .NET.