请问大家这样写程序目的何在呢??
procedure A;
   procedure B;
   begin   // do something
   end;
begin
   do somethin;
end;例程中又包含例程的写法有什么好处???把它们分开写有什么不同???
另外:从网上抄来的代码,用于对stringGrid排序
procedure TForm1.stringGri1MouseDown(sennder: Tobject; button: TMouseButton; Shift: TShiftState;x,y: integer);
{$J+}
const vOldCol: integer=-1;
{$J-}
var  vCol,Vrow: integer;
begin
 if (button=mbRight ) then exit;
 TStringGrid1(sender).MouseToCell(x,y,Vcol,vRow);
  with (sender as TStringGrid) do
  begin
    if (vRow<0) or (vrow >=TStringGrid(sender).fixedRows) then exit;
    RowSort(vcol,voldcol=vcol);   //Rowsort 负责对grid排序, vOldCol=Vcol 的值用来决定以升序还是降序来排序
    if vOldCol=vCol then
       vOldCol:=-vOldCol
    else
       voldCol:=vCol
  end;
end;不懂的地方:
1、vOldCol声明是个常量,为什么可以赋值??
2、vOldCol是在过程内部声明的,当执行权离开此过程时,vOldCol值应该丢掉,但测试结果表明vOldCol却记住上次执行的值。 
3、{J+}、{J-} 的作用是什么?还有:
delphi程序中应该如何捕获sql server执行sql语句时的错误?? 本人不是很了解其方案原理,希望大侠给点程序代码参考小弟在此先谢了。。

解决方案 »

  1.   

    {$J+}
    const vOldCol: integer=-1;
    {$J-}编译开关,可以给常量付值
      

  2.   

    1.函数内包含函数主要是作用域的不同2.类似于C里的Static变量3.系统消息
      

  3.   

    delphi程序中应该如何捕获sql server执行sql语句时的错误?? with adoquery do
    begin
      Close;
      SQL.Clear;
      SQL.Text := 'select * from table';
    try
      Open; //or ExecSQL,这个不返回结果
    except
     showmessage('Error!');
    end;
    end;
      

  4.   

    procedure A;
       procedure B;
       begin   // do something
       end;
    begin
       do somethin;
    end;
    过程、函数的目的就是实现某种接口 具有一定的封装性
    然后你再把它变为inner procedure 这样它的可见度就只有它的父procedure了 达到了信息隐藏 从而更安全。。