ChatBox

TsgcHTMLComponent_ChatBox — un riquadro chat a bolle in stile card con messaggi a sinistra/destra, avatar, una barra di input e un indicatore di digitazione animato, in Delphi, C++ Builder e .NET.

TsgcHTMLComponent_ChatBox

Un componente chat leggero che emette una card Bootstrap 5 con bolle di messaggio scorrevoli e una barra di input opzionale. Aggiungi i messaggi, imposta alcune proprietà, quindi leggi la proprietà HTML.

Classe del componente

TsgcHTMLComponent_ChatBox

Renderizza

Bootstrap 5 card + scoped CSS

Famiglia

Chat e IA

Linguaggi

Delphi, C++ Builder, .NET

Crealo, aggiungi i messaggi, renderizzalo

Imposta Title e Height, inserisci alcuni messaggi con AddMessage (scegliendo caLeft o caRight), quindi leggi HTML (oppure inseriscilo in una pagina TsgcHTMLTemplate_Bootstrap).

uses
  sgcHTML_Enums, sgcHTML_Component_ChatBox;

var
  oChat: TsgcHTMLComponent_ChatBox;
begin
  oChat := TsgcHTMLComponent_ChatBox.Create(nil);
  try
    oChat.Title := 'Support';
    oChat.Height := '400px';
    oChat.ShowInput := True;
    oChat.InputPlaceholder := 'Type a message...';
    oChat.ShowTypingIndicator := True;

    oChat.AddMessage('Alice', 'Hi, how can I help?', caLeft, hcSecondary);
    oChat.AddMessage('You', 'My order has not arrived.', caRight, hcPrimary);

    WebModule.Response := oChat.HTML;   // Bootstrap card + chat bubbles
  finally
    oChat.Free;
  end;
end;

// Append a single new bubble (e.g. over a WebSocket push):
oChat.AddMessage('Alice', 'Let me check that for you.', caLeft);
WebSocket.WriteData(oChat.GetLastMessageHTML);
// includes: sgcHTML_Enums.hpp, sgcHTML_Component_ChatBox.hpp

TsgcHTMLComponent_ChatBox *oChat = new TsgcHTMLComponent_ChatBox(NULL);
try
{
  oChat->Title = "Support";
  oChat->Height = "400px";
  oChat->ShowInput = true;
  oChat->InputPlaceholder = "Type a message...";
  oChat->ShowTypingIndicator = true;

  oChat->AddMessage("Alice", "Hi, how can I help?", caLeft, hcSecondary);
  oChat->AddMessage("You", "My order has not arrived.", caRight, hcPrimary);

  String html = oChat->HTML;   // Bootstrap card + chat bubbles
}
__finally
{
  delete oChat;
}
using esegece.sgcWebSockets;

var chat = new TsgcHTMLComponent_ChatBox();
chat.Title = "Support";
chat.Height = "400px";
chat.ShowInput = true;
chat.InputPlaceholder = "Type a message...";
chat.ShowTypingIndicator = true;

chat.AddMessage("Alice", "Hi, how can I help?", TsgcHTMLChatAlign.caLeft, TsgcHTMLColor.hcSecondary);
chat.AddMessage("You", "My order has not arrived.", TsgcHTMLChatAlign.caRight, TsgcHTMLColor.hcPrimary);

string html = chat.HTML;   // Bootstrap card + chat bubbles

Proprietà e metodi principali

I membri che utilizzerai più spesso.

Messaggi

Messages è una collezione TsgcHTMLChatMessages; ogni TsgcHTMLChatMessage porta Sender, Text, Timestamp, Align (caLeft/caRight), Color e AvatarInitials.

Aggiungere un messaggio

AddMessage(aSender, aText, aAlign, aColor, aTimestamp) aggiunge una bolla; le iniziali dell’avatar e l’ora vengono compilate automaticamente quando omesse.

Barra di input

ShowInput attiva/disattiva il modulo; InputPlaceholder, SendButtonText e SendButtonStyle (un TsgcHTMLButtonStyle) controllano il campo di composizione.

Intestazione e digitazione

Title imposta l’intestazione della card; ShowTypingIndicator mostra i puntini animati e TypingText ne imposta l’etichetta.

Identità e dimensione

ChatID assegna gli id degli elementi; Height delimita l’area di scorrimento (scorre automaticamente fino al messaggio più recente).

Output

HTML restituisce l’intera card; GetLastMessageHTML restituisce solo la bolla più recente — ideale per inviare un singolo aggiornamento tramite WebSocket.

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.