Tableau dynamique TRadioButton erreur

retaks666 Messages postés 286 Date d'inscription jeudi 2 janvier 2003 Statut Membre Dernière intervention 16 juillet 2007 - 13 oct. 2006 à 12:27
f0xi Messages postés 4205 Date d'inscription samedi 16 octobre 2004 Statut Modérateur Dernière intervention 12 mars 2022 - 14 oct. 2006 à 08:00
Salut à tous. J'ai un PageControl dans lequel je je créé dynamiquement des TTabSheet avec dedans un GroupBox et des RadiosButton.
j'ai donc des variables globales définies comme cela:
  tabsteps : array of TTabSheet;
  gbs : array of TGroupBox;
  rdb : array of array of TRadioButton;

La création des onglets et des TGroupBox se passe bien, mais lorsque je créé les radiobutton j'ai une erreur. Voici le code:

    for I := 0 to high(rdb[index]) - 1 do
         rdb[index][i].Free;



    setlength(rdb[index],0);

UIBQuery.SQL.Clear;
    UIBQuery.SQL.Text:='SELECT DISTINCT ' + fieldname + ' FROM "SEG$' + cmbtables.Text + '"';
    UIBQuery.Open();
    while not UIBQuery.Eof do
    begin
        i:=high(RDB[index]);



        if (i<0) then i:=0;
        setlength(RDB[index],i+1);



        showmessage(inttostr(i+1) + ' '  + inttostr(high(RDB[index]))); //obtiens 1 0
        RDB[index][i-1]:=TRadioButton.create(gbs[index]);
        showmessage(inttostr(i+1) + ' '  + inttostr(high(RDB[index]))); //obtiens 1 12525455
        RDB[index][i-1].Parent:=gbs[index];
        showmessage(inttostr(i+1) + ' '  + inttostr(high(RDB[index]))); //obtiens 1 12525455



        if not (high(RDB[index]) > 0) then //sauté car erreur avec le high
           RDB[index][0].Top :=20
        else
           RDB[index][i-1].Top :=RDB[index][i-2].Top + 30; //ici élément non accessible donc erreur d'accès mémoire



        RDB[index][i-1].Height:=20;
        RDB[index][i-1].left:=20;
        RDB[index][i-1].width:=gbs[index].Width-40;
        RDB[index][i-1].Visible:=true;
        RDB[index][i-1].Caption:=UIBQuery.Fields.AsString[0];




     if(UPPERCASE(fieldname)='"SEGMENTATION_NAME') then
     begin
            RDB[index][i-1].OnClick:=rdSegmentationclick;
     end;
    UIBQuery.Next;
    end;
    UIBQuery.Close();





L'erreur viens donc de la création du TRadioButton, mais je ne vois pas pourquoi ça ne marches pas, si quelqu'un a une solution je suis preneur !

3 réponses

cs_Jean_Jean Messages postés 615 Date d'inscription dimanche 13 août 2006 Statut Membre Dernière intervention 13 décembre 2018 3
13 oct. 2006 à 12:51
Bonjour,
[javascript:Insert_Emoticon('/imgs2/smile_angry.gif'); ]Dommage, je ne peux pas tester ton code car je n'ai pas SQL!
[javascript:Insert_Emoticon('/imgs2/smile_question.gif'); ]Tu as essayé avec un autre type de contrôle comme des cases à cocher par exemple.
[javascript:Insert_Emoticon('/imgs2/smile_wink.gif'); ]Oui, je sais, tu veux sans doute des radio-buttons, mais ça permettrait de voir que c'est bien le composant radiobutton qui est en cause.
Si ça marche avec les cases à cocher, c'est qu'il doit y avoir une propriété manquante ou non renseignée dans une classe intermédiaire dans la hiérarchie d'objet. Leur classe ancêtre commune est BoutonControl.
Tabsheet et Page Control sont plus éloignés dans la hiérarchie.
[javascript:Insert_Emoticon('/imgs2/smile_tongue.gif'); ]Je dis ça, mais c'est facile en théorie, ça serait mieux de tomber sur qlq qui a eu ce prob
Bien à toi
Jean_Jean
0
retaks666 Messages postés 286 Date d'inscription jeudi 2 janvier 2003 Statut Membre Dernière intervention 16 juillet 2007
13 oct. 2006 à 13:11
Apparement, ça ne changeais rien avec autrechose qu'un RadioButton, mais merci quand même :)
Bon j'ai modifié mon code, ça marche, mais j'ai pas la moindre idée du pouquoi...
(ce n'est pas les length, j'avias déja essayé)
Le voici pour ceux que ça intéresse:
procedure tfrmmain.loadradios(index:integer; fieldname : string);
var i : integer;
begin
    for I := 0 to high(rdb[index]) - 1 do
         rdb[index][i].Free;



    setlength(rdb[index],0);
    UIBQuery.SQL.Clear;
    UIBQuery.SQL.Text:='SELECT DISTINCT ' + fieldname + ' FROM "SEG$' + cmbtables.Text + '"';
    UIBQuery.Open();
    while not UIBQuery.Eof do
    begin
        i:=length(RDB[index]);



        if (i<0) then i:=0;
        setlength(RDB[index],i+1);



        RDB[index][i]:=TRadioButton.create(gbs[index]);
        //RDB[index][i].Parent:=tabsteps[index];



        RDB[index][i].Top :=30*(i+1);



        RDB[index][i].Height:=20;
        RDB[index][i].left:=20;
        RDB[index][i].width:=gbs[index].Width-40;
        RDB[index][i].Visible:=true;
        RDB[index][i].Caption:=UIBQuery.Fields.AsString[0];



     if(UPPERCASE(fieldname)='"SEGMENTATION_NAME') then
     begin
            RDB[index][i].OnClick:=rdSegmentationclick;
     end;
        RDB[index][i].parent:=GBS[index];



    UIBQuery.Next;
    end;
    UIBQuery.Close();
end;
0
f0xi Messages postés 4205 Date d'inscription samedi 16 octobre 2004 Statut Modérateur Dernière intervention 12 mars 2022 35
14 oct. 2006 à 08:00
procedure tfrmmain.loadradios(index:integer; fieldname : string);
var i : integer;
begin
    for i := 0 to high(rdb[index]) do
        rdb[index,i].Free;
    setlength(rdb[index],0);
    with UIBQuery do begin
        SQL.Clear;
        SQL.Text := 'SELECT DISTINCT ' + fieldname + ' FROM "SEG$' + cmbtables.Text + '"';
        Open;
        i := 0;
        while not Eof do begin
            inc(i);
            setlength(RDB[index], i);
            RDB[index,i-1] := TRadioButton.create(gbs[index]);
            with RDB[index,i-1] do begin
                Top     := 30 * (i);
                Left    := 20;
                Width   := gbs[index].Width - 40;
                Height  := 20;
                Caption := UIBQuery.Fields.AsString[0];
                if UpperCase(fieldname) = '"SEGMENTATION_NAME' then
                   OnClick := rdSegmentationclick;
                parent  := gbs[index];
            end;
            Next;
        end;
        Close;
    end;   
end;







0
Rejoignez-nous