<div dir="ltr">Me parece que tu ejemplo hace eso, cual es el problema?</div><div class="gmail_extra"><br><div class="gmail_quote">El 22 de junio de 2017, 10:01, Ismael L. Donis Garcia via Lazarus-es <span dir="ltr"><<a href="mailto:lazarus-es@lists.lazarus-ide.org" target="_blank">lazarus-es@lists.lazarus-ide.org</a>></span> escribió:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u>
<div bgcolor="#ffffff">
<div><font face="Arial" size="2">Llevo varios días tratando de visualizar las
existencias en un grid y por más que doy para atrás y para delante no doy pie
con bola.</font></div>
<div><font face="Arial" size="2"></font> </div>
<div><font face="Arial" size="2">Alguien ha logrado hacer esto utilizando un
MenDataset?</font></div>
<div><font face="Arial" size="2">Como podría lograrlo?</font></div>
<div><font face="Arial" size="2"></font> </div>
<div><font face="Arial" size="2">Aquí les paso un pequeño ejemplo de lo que quiero
hacer.</font></div>
<div><font face="Arial" size="2"></font> </div>
<div><font face="Arial" size="2">Quiero que al moverme por el grid y
llegue a la columna de la cantidad me sume a las existencias la
cantidad y cuando salga de la columna me reste la cantidad. El grid es editable,
ósea debe permitir agregar datos y cambiarle los valores de la algunas columnas,
dentro de ellas la de la cantidad.</font></div>
<div><font face="Arial" size="2"></font> </div>
<div><font face="Arial" size="2">unit Unit1;</font></div>
<div> </div>
<div><font face="Arial" size="2">{$mode objfpc}{$H+}</font></div>
<div> </div>
<div><font face="Arial" size="2">interface</font></div>
<div> </div>
<div><font face="Arial" size="2">uses<br> Classes, SysUtils, memds, FileUtil,
Forms, Controls, Graphics, Dialogs,<br> DBGrids, StdCtrls, db,
Grids;</font></div>
<div> </div><font face="Arial" size="2">
<div><br>type</div>
<div> </div>
<div> { TForm1 }</div>
<div> </div>
<div> TForm1 = class(TForm)<br> DataSource1:
TDataSource;<br> DBGrid1: TDBGrid;<br>
Edit1: TEdit;<br> MemDataset1:
TMemDataset;<br> procedure DBGrid1SelectEditor(Sender:
TObject; Column: TColumn;<br> var Editor:
TWinControl);<br> procedure FormCreate(Sender:
TObject);<br> procedure MemDataset1BeforeScroll(<wbr>DataSet:
TDataSet);<br> private<br> { private declarations
}<br> icol: longint;<br> public<br> {
public declarations }<br> end;</div>
<div> </div>
<div>var<br> Form1: TForm1;</div>
<div> </div>
<div>implementation</div>
<div> </div>
<div>{$R *.lfm}</div>
<div> </div>
<div>{ TForm1 }</div>
<div> </div>
<div>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>
DataSource1.DataSet:=<wbr>MemDataset1;<br>
DBGrid1.DataSource:=<wbr>DataSource1;<br> MemDataset1.FieldDefs.Add('<wbr>codigo',
ftString, 12);<br> MemDataset1.FieldDefs.Add('<wbr>cod', ftString,
4);<br> MemDataset1.FieldDefs.Add('<wbr>elemusd', ftString, 7);<br>
MemDataset1.FieldDefs.Add('<wbr>elemmn', ftString,
7);<br> MemDataset1.FieldDefs.Add('<wbr>cantidad',
ftFloat);<br> MemDataset1.FieldDefs.Add('<wbr>saldo2',
ftFloat);<br> MemDataset1.FieldDefs.Add('<wbr>saldo1',
ftFloat);<br> MemDataset1.FieldDefs.Add('<wbr>exist', ftFloat);<br>
MemDataset1.Open;<br> DBGrid1.Columns.Items[0].<wbr>Title.Caption :=
'Código';<br> DBGrid1.Columns.Items[0].<wbr>Width:=115;<br>
DBGrid1.Columns.Items[0].<wbr>ReadOnly:=true;<br>
DBGrid1.Columns.Items[1].<wbr>Title.Caption := 'Cod';<br>
DBGrid1.Columns.Items[1].<wbr>Title.Alignment:=taCenter;<br>
DBGrid1.Columns.Items[1].<wbr>Alignment:=taCenter;<br> DBGrid1.Columns.Items[1].<wbr>Width:=58;<br> DBGrid1.Columns.Items[1].<wbr>ButtonStyle:=cbsEllipsis;<br>
DBGrid1.Columns.Items[2].<wbr>Title.Caption := 'Elem CUC';<br>
DBGrid1.Columns.Items[2].<wbr>Title.Alignment:=taCenter;<br>
DBGrid1.Columns.Items[2].<wbr>Alignment:=taCenter;<br> DBGrid1.Columns.Items[2].<wbr>Width:=72;<br> DBGrid1.Columns.Items[2].<wbr>ButtonStyle:=cbsEllipsis;<br>
DBGrid1.Columns.Items[3].<wbr>Title.Caption := 'Elem CUP';<br>
DBGrid1.Columns.Items[3].<wbr>Title.Alignment:=taCenter;<br>
DBGrid1.Columns.Items[3].<wbr>Alignment:=taCenter;<br> DBGrid1.Columns.Items[3].<wbr>Width:=72;<br> DBGrid1.Columns.Items[3].<wbr>ButtonStyle:=cbsEllipsis;<br>
DBGrid1.Columns.Items[4].<wbr>Title.Caption := 'Cantidad';<br>
DBGrid1.Columns.Items[4].<wbr>Title.Alignment:=taCenter;<br> DBGrid1.Columns.Items[4].<wbr>Alignment:=taRightJustify;<br> DBGrid1.Columns.Items[4].<wbr>Width:=90;<br> DBGrid1.Columns.Items[4].<wbr>DisplayFormat:='###0.000';<br>
DBGrid1.Columns.Items[5].<wbr>Title.Caption := 'Valor CUC';<br>
DBGrid1.Columns.Items[5].<wbr>Title.Alignment:=taCenter;<br> DBGrid1.Columns.Items[5].<wbr>Alignment:=taRightJustify;<br> DBGrid1.Columns.Items[5].<wbr>Width:=90;<br> DBGrid1.Columns.Items[5].<wbr>DisplayFormat:='###0.00';<br>
DBGrid1.Columns.Items[6].<wbr>Title.Caption := 'Valor CUP';<br>
DBGrid1.Columns.Items[6].<wbr>Title.Alignment:=taCenter;<br> DBGrid1.Columns.Items[6].<wbr>Alignment:=taRightJustify;<br> DBGrid1.Columns.Items[6].<wbr>Width:=90;<br> DBGrid1.Columns.Items[6].<wbr>DisplayFormat:='###0.00';<br>
DBGrid1.Columns.Items[7].<wbr>Title.Caption := 'Existencia';<br>
DBGrid1.Columns.Items[7].<wbr>Title.Alignment:=taCenter;<br> DBGrid1.Columns.Items[7].<wbr>Alignment:=taRightJustify;<br> DBGrid1.Columns.Items[7].<wbr>Width:=85;<br> DBGrid1.Columns.Items[7].<wbr>DisplayFormat:='###0.000';</div>
<div> </div>
<div> MemDataset1.Append;<br>
MemDataset1.FieldByName('<wbr>codigo').AsString:='100.100.<wbr>0001';<br>
MemDataset1.FieldByName('cod')<wbr>.AsString:='801';<br>
MemDataset1.FieldByName('<wbr>elemusd').AsString:='2013';<br>
MemDataset1.FieldByName('<wbr>elemmn').AsString:='2014';<br>
MemDataset1.FieldByName('<wbr>cantidad').AsFloat:=1.000;<br>
MemDataset1.FieldByName('<wbr>saldo1').AsFloat:=12.5;<br>
MemDataset1.FieldByName('<wbr>saldo2').AsFloat:=10.3;<br>
MemDataset1.FieldByName('<wbr>exist').AsFloat:=4;<br>
MemDataset1.UpdateRecord;<br> MemDataset1.Post;<br>
MemDataset1.Append;<br>
MemDataset1.FieldByName('<wbr>codigo').AsString:='100.100.<wbr>0002';<br>
MemDataset1.FieldByName('cod')<wbr>.AsString:='801';<br>
MemDataset1.FieldByName('<wbr>elemusd').AsString:='2013';<br>
MemDataset1.FieldByName('<wbr>elemmn').AsString:='2014';<br>
MemDataset1.FieldByName('<wbr>cantidad').AsFloat:=2.000;<br>
MemDataset1.FieldByName('<wbr>saldo1').AsFloat:=18.5;<br>
MemDataset1.FieldByName('<wbr>saldo2').AsFloat:=6.3;<br>
MemDataset1.FieldByName('<wbr>exist').AsFloat:=8;<br>
MemDataset1.UpdateRecord;<br> MemDataset1.Post;</div>
<div> </div>
<div> icol:=0;<br>end;</div>
<div> </div>
<div>procedure TForm1.<wbr>MemDataset1BeforeScroll(<wbr>DataSet:
TDataSet);<br>begin<br> if (icol = 4) then begin<br> if not
(DBGrid1.DataSource.DataSet.<wbr>State in dsEditModes) then<br>
DBGrid1.DataSource.DataSet.<wbr>Edit;<br>
DBGrid1.DataSource.DataSet.<wbr>FieldByName('exist').AsFloat:=<wbr>DBGrid1.DataSource.DataSet.<wbr>FieldByName('exist').AsFloat
- DBGrid1.DataSource.DataSet.<wbr>FieldByName('cantidad').<wbr>AsFloat;<br>
end;<br>end;</div>
<div> </div>
<div>procedure TForm1.DBGrid1SelectEditor(<wbr>Sender: TObject; Column:
TColumn;<br> var Editor: TWinControl);<br>begin<br> if (Column.Index
= 4) then begin<br> if not (DBGrid1.DataSource.DataSet.<wbr>State
in dsEditModes) then<br>
DBGrid1.DataSource.DataSet.<wbr>Edit;<br>
DBGrid1.DataSource.DataSet.<wbr>FieldByName('exist').AsFloat:=<wbr>DBGrid1.DataSource.DataSet.<wbr>FieldByName('exist').AsFloat
+ DBGrid1.DataSource.DataSet.<wbr>FieldByName('cantidad').<wbr>AsFloat;<br> end else
if (icol = 4) then begin<br> if not
(DBGrid1.DataSource.DataSet.<wbr>State in dsEditModes) then<br>
DBGrid1.DataSource.DataSet.<wbr>Edit;<br>
DBGrid1.DataSource.DataSet.<wbr>FieldByName('exist').AsFloat:=<wbr>DBGrid1.DataSource.DataSet.<wbr>FieldByName('exist').AsFloat
- DBGrid1.DataSource.DataSet.<wbr>FieldByName('cantidad').<wbr>AsFloat;<br>
end;<br> icol := Column.Index;<br>end;</div>
<div> </div>
<div>end. </div></font></div>
<div><font face="Arial" size="2"></font> </div>
<div><font face="Arial" size="2">Saludos</font></div>
<div><font face="Arial" size="2">--<br>ISMAEL<br>Devuan User : <a href="http://distrowatch.com/table.php?distribution=devuan" target="_blank">http://distrowatch.com/table.<wbr>php?distribution=devuan</a></font></div>
<br>______________________________<wbr>_________________<br>
Lazarus-es mailing list<br>
<a href="mailto:Lazarus-es@lists.lazarus-ide.org">Lazarus-es@lists.lazarus-ide.<wbr>org</a><br>
<a href="http://lists.lazarus-ide.org/listinfo/lazarus-es" rel="noreferrer" target="_blank">http://lists.lazarus-ide.org/<wbr>listinfo/lazarus-es</a><br>
<br></blockquote></div><br></div>