<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.5512" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY 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(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:=MemDataset1;<BR>  
DBGrid1.DataSource:=DataSource1;<BR>  MemDataset1.FieldDefs.Add('codigo', 
ftString, 12);<BR>  MemDataset1.FieldDefs.Add('cod', ftString, 
4);<BR>  MemDataset1.FieldDefs.Add('elemusd', ftString, 7);<BR>  
MemDataset1.FieldDefs.Add('elemmn', ftString, 
7);<BR> MemDataset1.FieldDefs.Add('cantidad', 
ftFloat);<BR> MemDataset1.FieldDefs.Add('saldo2', 
ftFloat);<BR> MemDataset1.FieldDefs.Add('saldo1', 
ftFloat);<BR> MemDataset1.FieldDefs.Add('exist', ftFloat);<BR>  
MemDataset1.Open;<BR> DBGrid1.Columns.Items[0].Title.Caption := 
'Código';<BR> DBGrid1.Columns.Items[0].Width:=115;<BR>  
DBGrid1.Columns.Items[0].ReadOnly:=true;<BR>  
DBGrid1.Columns.Items[1].Title.Caption := 'Cod';<BR>  
DBGrid1.Columns.Items[1].Title.Alignment:=taCenter;<BR>  
DBGrid1.Columns.Items[1].Alignment:=taCenter;<BR> DBGrid1.Columns.Items[1].Width:=58;<BR> DBGrid1.Columns.Items[1].ButtonStyle:=cbsEllipsis;<BR>  
DBGrid1.Columns.Items[2].Title.Caption := 'Elem CUC';<BR>  
DBGrid1.Columns.Items[2].Title.Alignment:=taCenter;<BR>  
DBGrid1.Columns.Items[2].Alignment:=taCenter;<BR> DBGrid1.Columns.Items[2].Width:=72;<BR> DBGrid1.Columns.Items[2].ButtonStyle:=cbsEllipsis;<BR>  
DBGrid1.Columns.Items[3].Title.Caption := 'Elem CUP';<BR>  
DBGrid1.Columns.Items[3].Title.Alignment:=taCenter;<BR>  
DBGrid1.Columns.Items[3].Alignment:=taCenter;<BR> DBGrid1.Columns.Items[3].Width:=72;<BR> DBGrid1.Columns.Items[3].ButtonStyle:=cbsEllipsis;<BR>  
DBGrid1.Columns.Items[4].Title.Caption := 'Cantidad';<BR>  
DBGrid1.Columns.Items[4].Title.Alignment:=taCenter;<BR> DBGrid1.Columns.Items[4].Alignment:=taRightJustify;<BR> DBGrid1.Columns.Items[4].Width:=90;<BR> DBGrid1.Columns.Items[4].DisplayFormat:='###0.000';<BR>  
DBGrid1.Columns.Items[5].Title.Caption := 'Valor CUC';<BR>  
DBGrid1.Columns.Items[5].Title.Alignment:=taCenter;<BR> DBGrid1.Columns.Items[5].Alignment:=taRightJustify;<BR> DBGrid1.Columns.Items[5].Width:=90;<BR> DBGrid1.Columns.Items[5].DisplayFormat:='###0.00';<BR>  
DBGrid1.Columns.Items[6].Title.Caption := 'Valor CUP';<BR>  
DBGrid1.Columns.Items[6].Title.Alignment:=taCenter;<BR> DBGrid1.Columns.Items[6].Alignment:=taRightJustify;<BR> DBGrid1.Columns.Items[6].Width:=90;<BR> DBGrid1.Columns.Items[6].DisplayFormat:='###0.00';<BR>  
DBGrid1.Columns.Items[7].Title.Caption := 'Existencia';<BR>  
DBGrid1.Columns.Items[7].Title.Alignment:=taCenter;<BR> DBGrid1.Columns.Items[7].Alignment:=taRightJustify;<BR> DBGrid1.Columns.Items[7].Width:=85;<BR> DBGrid1.Columns.Items[7].DisplayFormat:='###0.000';</DIV>
<DIV> </DIV>
<DIV>  MemDataset1.Append;<BR>  
MemDataset1.FieldByName('codigo').AsString:='100.100.0001';<BR>  
MemDataset1.FieldByName('cod').AsString:='801';<BR>  
MemDataset1.FieldByName('elemusd').AsString:='2013';<BR>  
MemDataset1.FieldByName('elemmn').AsString:='2014';<BR>  
MemDataset1.FieldByName('cantidad').AsFloat:=1.000;<BR>  
MemDataset1.FieldByName('saldo1').AsFloat:=12.5;<BR>  
MemDataset1.FieldByName('saldo2').AsFloat:=10.3;<BR>  
MemDataset1.FieldByName('exist').AsFloat:=4;<BR>  
MemDataset1.UpdateRecord;<BR>  MemDataset1.Post;<BR>  
MemDataset1.Append;<BR>  
MemDataset1.FieldByName('codigo').AsString:='100.100.0002';<BR>  
MemDataset1.FieldByName('cod').AsString:='801';<BR>  
MemDataset1.FieldByName('elemusd').AsString:='2013';<BR>  
MemDataset1.FieldByName('elemmn').AsString:='2014';<BR>  
MemDataset1.FieldByName('cantidad').AsFloat:=2.000;<BR>  
MemDataset1.FieldByName('saldo1').AsFloat:=18.5;<BR>  
MemDataset1.FieldByName('saldo2').AsFloat:=6.3;<BR>  
MemDataset1.FieldByName('exist').AsFloat:=8;<BR>  
MemDataset1.UpdateRecord;<BR>  MemDataset1.Post;</DIV>
<DIV> </DIV>
<DIV>  icol:=0;<BR>end;</DIV>
<DIV> </DIV>
<DIV>procedure TForm1.MemDataset1BeforeScroll(DataSet: 
TDataSet);<BR>begin<BR> if (icol = 4) then begin<BR>  if not 
(DBGrid1.DataSource.DataSet.State in dsEditModes) then<BR>  
  DBGrid1.DataSource.DataSet.Edit;<BR>   
DBGrid1.DataSource.DataSet.FieldByName('exist').AsFloat:=DBGrid1.DataSource.DataSet.FieldByName('exist').AsFloat 
- DBGrid1.DataSource.DataSet.FieldByName('cantidad').AsFloat;<BR>  
end;<BR>end;</DIV>
<DIV> </DIV>
<DIV>procedure TForm1.DBGrid1SelectEditor(Sender: TObject; Column: 
TColumn;<BR>  var Editor: TWinControl);<BR>begin<BR>  if (Column.Index 
= 4) then begin<BR>    if not (DBGrid1.DataSource.DataSet.State 
in dsEditModes) then<BR>      
DBGrid1.DataSource.DataSet.Edit;<BR>    
DBGrid1.DataSource.DataSet.FieldByName('exist').AsFloat:=DBGrid1.DataSource.DataSet.FieldByName('exist').AsFloat 
+ DBGrid1.DataSource.DataSet.FieldByName('cantidad').AsFloat;<BR> end else 
if (icol = 4) then begin<BR>   if not 
(DBGrid1.DataSource.DataSet.State in dsEditModes) then<BR>    
 DBGrid1.DataSource.DataSet.Edit;<BR>    
DBGrid1.DataSource.DataSet.FieldByName('exist').AsFloat:=DBGrid1.DataSource.DataSet.FieldByName('exist').AsFloat 
- DBGrid1.DataSource.DataSet.FieldByName('cantidad').AsFloat;<BR>  
end;<BR>  icol := Column.Index;<BR>end;</DIV>
<DIV> </DIV>
<DIV>end.     </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">http://distrowatch.com/table.php?distribution=devuan</A></FONT></DIV></BODY></HTML>