EOutOfResource RichEdit which change my policy?

307 views Asked by At

I'm working on an multiThreaded server with a VCL form used for maintenance of the system. Each thread can write on a RichEdit of the MainForm to show what it does in real time (If an issue occurs, we must fix this quickly).

But, when a thread writes to the RichEdit, I from time to time get an "EOutOfResource" error: "Erreur d'insertion de ligne RichEdit" (Google translate: Error insertion line RichEdit). The RichEdit contents become a mess.

This is the main form procedure that adds add a line on the RichEdit:

procedure Main.MajRichEdit(S1,S2:string;tform:TFontStyles;i1:integer)
begin
    CriticalSection.Acquire
    if S2='C' then
    begin
        RichEditC.SelAttributes.Style:=tform;
        RichEditC.SelAttributes.Color:=i1;
        RichEditC.Lines.Add:=S1;
    end
    else if S2='CN' then
        RichEditC.Lines.Add:=S1;

    else if S2='T' then
    begin
        RichEditT.SelAttributes.Style:=tform;
        RichEditT.SelAttributes.Color:=i1;
        RichEditT.Lines.Add:=S1;
    end
    else if S2='TN' then
        RichEditT.Lines.Add:=S1;

    else if S2='S' then
    begin
        RichEditS.SelAttributes.Style:=tform;
        RichEditS.SelAttributes.Color:=i1;
        RichEditS.Lines.Add:=S1;
    end
    else if S2='SN' then
        RichEditS.Lines.Add:=S1;
    CriticalSection.Release;
end;

These are the calls from my threads:

//..Declaration Variable..//
public
    sCall1,sCall2:string;
    tFontCall1:TFontStyles;
    iNbColor1:integer;
//..Appel MajRichEdit..//
procedure Mythread.CallREMajTelforIHM;
begin
    LockIHM.BeginWrite;
    Main.MajRichEdit(sCall1,sCall2,tFontCall1,iNbColor1);
    LockIHM.EndWrite;
end;
//..Appel CallRe ..//
//My code
    sCall1:="un petit peu de français , c'est pas plus mal ;) "
    sCall2:="C";
    tFontCall1:=[fsBold]; //If i want a txt in bold ;)
    iCall1:=clRed;
    Queue(CallREMajTelforIHM);

I have similar stuff working fine (just a EAccessViolation for one little thing but i will repair that after ;) )

The Exception could be bypassed with a try/except? I do nothing in my system for change that so i don't understand why the TRichEdit policy is modified...

0

There are 0 answers