StringGrid vers memo

shadow578 Messages postés 102 Date d'inscription mercredi 8 avril 2009 Statut Membre Dernière intervention 27 juin 2011 - 15 oct. 2009 à 16:50
shadow578 Messages postés 102 Date d'inscription mercredi 8 avril 2009 Statut Membre Dernière intervention 27 juin 2011 - 16 oct. 2009 à 11:23
Salut internaute,
Alors voilà me voici avec un nouveau soucis.
Dans un premier temps j'ai un stringgrid qui li dans un fichier text, j'ai fait un scrit pour que dés que j'ai le mot erreur (dans la 5éme colone) cela s'affiche en rouge, sa c'est OK.
Maintenant j'aimerai savoir comment afficher dans un memo ou dans un stringgrid chaque ligne où il y a une erreur?

Vous avez compris ? :D

En image: voila mon logiciel avec les lignes rouge



Et donc j'aimerai que toute les ligne rouge soit rassembler dans un autre stringgrid.

merci ;)

13 réponses

shadow578 Messages postés 102 Date d'inscription mercredi 8 avril 2009 Statut Membre Dernière intervention 27 juin 2011 1
16 oct. 2009 à 09:24
[b]Alors tout à fait c'est après la pression du bouton "lire fichier" que les infos apparaisse dans le tableau est donc en même temps dans l'autre tableau
unit Unit1;

interface

uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, ImgList, inifiles, Registry, Shellapi,
  MPlayer, Grids, jpeg, StrUtils, ComCtrls, XPMan, Gauges;

type
  TForm1 = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    GroupBox1: TGroupBox;
    Button1: TButton;
    Button2: TButton;
    StringGrid1: TStringGrid;
    Memo1: TMemo;
    TabSheet2: TTabSheet;
    XPManifest1: TXPManifest;
    ProgressBar1: TProgressBar;
    StringGrid2: TStringGrid;

    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
  private
    { Déclarations privées }
  public
    { Déclarations publiques }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


function extraire(var chaine:string; separateur: string):string;
var p: integer;
begin
  p := pos(separateur, chaine);
  if p = 0 then begin
    Result := chaine;
    chaine := '';
  end else begin
    result := copy(chaine, 1, p-1);
    delete(chaine, 1, p -1 + length(separateur));
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
Var F: TextFile;
    ligne: String;
    noLigne, noCol: integer;
     n1, n2: Variant;

begin
  n1 := 0;
  n2 := 0;
  ProgressBar1.Position := 0;
  while n1 < 500000 do
  begin
    n2 := n2 + n1;
    Inc (n1);
    if (n1 mod 5000) = 0 then
    begin
      ProgressBar1.Position := n1 div 5000;
      Application.ProcessMessages;
    end;
  end;


begin
  noLigne := 0;
  AssignFile(F,ExtractFilePath(Application.ExeName)+'test.txt');
  Reset(F);
  repeat

    Readln(F, ligne);
    inc(noLigne);
    if noLigne + 1 > StringGrid1.RowCount then
      StringGrid1.RowCount            := noLigne + 1;
    noCol := 0;
    repeat
      StringGrid1.Cells[noCol, noLigne] := extraire(ligne, #9);
      inc(noCol);
    until ligne = '';

    if  StringGrid1.Cells[5, noLigne] = 'erreur' then
      StringGrid1.Objects[0, noLigne]       := TObject(0)
    else
      StringGrid1.Objects[0, noLigne]       := TObject(1);
  until EOF(F);
  CloseFile(F);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin

application.terminate;

end;



procedure TForm1.FormShow(Sender: TObject);

begin
  StringGrid1.ColWidths[1] := 40;
  StringGrid1.ColWidths[2] := 40;
  StringGrid1.ColWidths[5] := 80;
  StringGrid1.ColWidths[3] := 100;
  StringGrid1.Rows[0].DelimitedText := '"N° de vol"'#9'"Date"'#9'"heure"'#9'"Nombre de ballon"'#9'"Activer"'#9'"Etat du laché"';

  end;

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  if ARow <> 0 then begin
    with StringGrid1, Canvas do begin
      if Objects[0, ARow] = Tobject(0) then
        Brush.Color := RGB(255, 200, 200)
      else
        Brush.Color := RGB(200, 255, 200);
      FillRect(Rect);
      DrawText(Canvas.Handle, PChar(Cells[ACol,ARow]), -1, Rect ,
               DT_CENTER or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE);

    end;
  end;
end;

end.
/b
1
cs_cantador Messages postés 4720 Date d'inscription dimanche 26 février 2006 Statut Modérateur Dernière intervention 31 juillet 2021 13
16 oct. 2009 à 09:16
bonjour,

Il faudrait préciser si tu souhaites récupérer ces lignes instantanément à l'ouverture du projet
où lors d'une autre opération..

Mais le principe reste le même :

faire une boucle sur les lignes en testant la valeur de la colonne 5 et stocker dans la foulée dans un TMemo.

peux-tu nous montrer un bout de code ?

cantador
0
JeremyLecouvert Messages postés 139 Date d'inscription mardi 27 novembre 2007 Statut Membre Dernière intervention 10 mai 2010 2
16 oct. 2009 à 09:47
Quand tu as identifié la ligne du 1° StringGrid que tu veux copier, tu fais

With StringGrid2 do
  Begin
    Inc(RowCount);
    Rows[RowCount-1].AddStrings(StringGrid1.Rows[IndexLigneACopier]);
  End;


Voilou!
0
shadow578 Messages postés 102 Date d'inscription mercredi 8 avril 2009 Statut Membre Dernière intervention 27 juin 2011 1
16 oct. 2009 à 09:51
Je n'est pas tout saisis

Je le mets dans le code du bouton qui affiche stringgrid 1 ?
begin
  noLigne := 0;
  AssignFile(F,ExtractFilePath(Application.ExeName)+'test.txt');
  Reset(F);
  repeat

    Readln(F, ligne);
    inc(noLigne);
    if noLigne + 1 > StringGrid1.RowCount then
      StringGrid1.RowCount            := noLigne + 1;
    noCol := 0;
    repeat
      StringGrid1.Cells[noCol, noLigne] := extraire(ligne, #9);
      inc(noCol);
    until ligne = '';

    if  StringGrid1.Cells[5, noLigne] = 'erreur' then
      StringGrid1.Objects[0, noLigne]       := TObject(0)
    else
      StringGrid1.Objects[0, noLigne]       := TObject(1);
With StringGrid2 do
  Begin
    Inc(RowCount);    Rows[RowCount1].AddStrings(StringGrid1.Rows[IndexLigneACopier]);
  End;
  until EOF(F);
  CloseFile(F);
end;
end;


??
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
JeremyLecouvert Messages postés 139 Date d'inscription mardi 27 novembre 2007 Statut Membre Dernière intervention 10 mai 2010 2
16 oct. 2009 à 10:05
Non, tu le mets directement dans ton "IF" quand tu testes la colonne 5:

    if StringGrid1.Cells[5, noLigne] = 'erreur' then
      Begin
        StringGrid1.Objects[0, noLigne]       := TObject(0);
        With StringGrid2 do
          Begin
            Inc(RowCount);
            Rows[RowCount1].AddStrings(StringGrid1.Rows[noLigneeACopier]);
          End;
      end
    else...
0
shadow578 Messages postés 102 Date d'inscription mercredi 8 avril 2009 Statut Membre Dernière intervention 27 juin 2011 1
16 oct. 2009 à 10:12
D'accord je vien de comprendre, par contre il me met plein de message d'erreur pour t'on:

Inc(RowCount); Rows[RowCount1].AddStrings(StringGrid1.Rows[noLigneeACopier]);
0
shadow578 Messages postés 102 Date d'inscription mercredi 8 avril 2009 Statut Membre Dernière intervention 27 juin 2011 1
16 oct. 2009 à 10:15
Il me mets "[Erreur] Unit1.pas(101): La partie gauche n'est pas affectable"

pour: Inc(RowCount);
0
JeremyLecouvert Messages postés 139 Date d'inscription mardi 27 novembre 2007 Statut Membre Dernière intervention 10 mai 2010 2
16 oct. 2009 à 10:23
abon.. dommage!

remplace-le par RowCount:= RowCount+1;
0
shadow578 Messages postés 102 Date d'inscription mercredi 8 avril 2009 Statut Membre Dernière intervention 27 juin 2011 1
16 oct. 2009 à 10:26
Quand j'exécute sa me mets un très jolie message d'erreur :D
0
JeremyLecouvert Messages postés 139 Date d'inscription mardi 27 novembre 2007 Statut Membre Dernière intervention 10 mai 2010 2
16 oct. 2009 à 10:46
Tu as peut-être mal incrémenté ton indice sur StringGrid2. Il t'envoie aussi ce message si tu essaies de faire un AddStrings dans une ligne déjà remplie.

2 solutions:
-vérifie en debug que tu essaies bien d'écrire dans la bonne ligne;
-si tu veux écrire dans une ligne déjà occupée, fais un "Rows[RowCount-1].Clear;" avant pour vider la ligne.

Après ça ça devrait aller..
0
shadow578 Messages postés 102 Date d'inscription mercredi 8 avril 2009 Statut Membre Dernière intervention 27 juin 2011 1
16 oct. 2009 à 10:59
Bon en faite j'ai changé un peut:

 
if StringGrid1.Cells[5, noLigne] = 'erreur' then
      Begin
        StringGrid1.Objects[0, noLigne]    := TObject(0);
        With StringGrid2 do
          Begin

            inc(RowCount1);
            RowCount := RowCount1+1;
            Rows[RowCount1].DelimitedText := StringGrid1.Rows[noLigne].DelimitedText;

          End;
      end
    else..



Et la sa marche ;) merci à toi de m'avoir bien mis sur la voie
0
JeremyLecouvert Messages postés 139 Date d'inscription mardi 27 novembre 2007 Statut Membre Dernière intervention 10 mai 2010 2
16 oct. 2009 à 11:17
..mais en fait y'a pas de RowCount1! Je vois pas ce qu'il vient faire là.. c'est:
RowCount:= RowCount+1;
Rows[RowCount-1]...


En regardant les posts précédents, je vois qu'au départ, j'avais bien écris "[RowCount-1]".. et pis tu l'as recopié ensuite en "RowCount1", et pis j'ai fait du copier/coller stupide... du coup on se retrouve avec une variable qui a rien à y foutre!!
0
shadow578 Messages postés 102 Date d'inscription mercredi 8 avril 2009 Statut Membre Dernière intervention 27 juin 2011 1
16 oct. 2009 à 11:23
ah oui en effet, bon enfin bref maintenant sa marche :D
merci à toi ;)
0
Rejoignez-nous