DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: lixuan123
今日帖子: 0
在线用户: 0
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 jsnjsmc (鱼) ★☆☆☆☆ -
盒子活跃会员
2004/1/13 9:05:31
标题:
请教个打印问题:谢谢!! 浏览:1816
加入我的收藏
楼主: 请看附件:
此帖子包含附件:jsnjsmc_20041139530.doc 大小:29.0K
----------------------------------------------
-
作者:
男 bios (阿贡) ★☆☆☆☆ -
盒子中级会员
2004/1/13 9:07:20
1楼: 晕怎么找偶呀!偶很差呀
偶自己没有打印机,可能很解决呀!
----------------------------------------------
按此在新窗口浏览图片
按此在新窗口浏览图片
作者:
男 jsnjsmc (鱼) ★☆☆☆☆ -
盒子活跃会员
2004/1/13 9:10:54
2楼: 不是打印机,我是说打印到文本文件;
----------------------------------------------
-
作者:
男 jsnjsmc (鱼) ★☆☆☆☆ -
盒子活跃会员
2004/1/13 9:11:38
3楼: StringGrid表格打印到文本文件;
----------------------------------------------
-
作者:
男 bios (阿贡) ★☆☆☆☆ -
盒子中级会员
2004/1/13 9:20:13
4楼: 哦 偶看看吧!
----------------------------------------------
按此在新窗口浏览图片
按此在新窗口浏览图片
作者:
男 bios (阿贡) ★☆☆☆☆ -
盒子中级会员
2004/1/13 9:23:46
5楼: 如果字符的长短不一定。
那 他们不好对起呀!
----------------------------------------------
按此在新窗口浏览图片
按此在新窗口浏览图片
作者:
男 jsnjsmc (鱼) ★☆☆☆☆ -
盒子活跃会员
2004/1/13 9:38:58
6楼: 有什么好的办法吗??
都是数值,能不能判一下让输入的字符让不足多少位加.000或空格

还想请教一个问题能不能在StringGrid里面输入的内容能象在MaskEdit那样格式化一下所输入的内容,如:第几位是数字,第几位是字符,


或者这样说你教我一个最简单的在StringGrid里面只能输入数字而且不能超过多少位.是不是要判断输入的键值,
----------------------------------------------
-
作者:
男 bios (阿贡) ★☆☆☆☆ -
盒子中级会员
2004/1/13 10:48:07
7楼: 偶试了一下 直接输入就判断 非常难的!

 至于 说:1)不足多少位加.000或空格
2)输入的内容能象在MaskEdit那样格式化一下所输入的内容
可以在 EDIT中或MASKEDIT中实现!

偶的算法是很简单 但 编译器无法实现!

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids;

type
  TForm1 = class(TForm)
    sg1: TStringGrid;
    Button1: TButton;
    procedure FormShow(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure sg1GetEditText(Sender: TObject; ACol, ARow: Integer;
      var Value: String);
    procedure sg1SetEditText(Sender: TObject; ACol, ARow: Integer;
      const Value: String);
    procedure sg1SelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  tts1:string;
implementation

{$R *.dfm}

procedure TForm1.FormShow(Sender: TObject);
var
 i:LOngint;

begin
  sg1.RowCount :=4;
  sg1.Colcount:=4;
  sg1.FixedCols :=1;
  sg1.FixedRows :=1;
  sg1.Cells[1,1]:='00001234';//全部8位 或 。。。更多 就可以对起!
  sg1.Cells[2,1]:='00012345';
  sg1.Cells[3,1]:='00123456';

  sg1.Cells[1,2]:='00123456';
  sg1.Cells[2,2]:='00012345';
  sg1.Cells[3,2]:='00000123';

  sg1.Cells[1,3]:='00000001';
  sg1.Cells[2,3]:='00000001';
  sg1.Cells[3,3]:='00452354';
  

end;

procedure TForm1.Button1Click(Sender: TObject);//打印
var
 i,j:Longint;
 path,s1,s2,sall:string;
 sl:TStringList;
begin
 sl:=TStringList.Create ;
 path:=extractfilepath(application.ExeName )+'test.txt';
 if fileexists(path) then deletefile(path);
 sall:=';
  for i:=1 to sg1.RowCount -1 do
   begin//2
      for j:=1 to sg1.colCount -1 do
        begin//1
           sall:=sall+sg1.Cells[j,i]+stringofchar(' ',10);//换行回车
        end;//1
     sall:=sall+#13#10;//换行回车
   end;//2
  sl.Clear ;
  sl.Add(sall);
  sl.SaveToFile(path);  
end;

procedure TForm1.sg1GetEditText(Sender: TObject; ACol, ARow: Integer;
  var Value: String);
var
 m1,m2:Longint;
 s1,s2:string;
begin
 {
 s1:=value;
 m1:=length(s1);
 if m1<8 then
  begin
   m2:=8-m1;
   value:=stringofchar('0',m2)+value;
  end;
 }
end;

procedure TForm1.sg1SetEditText(Sender: TObject; ACol, ARow: Integer;
  const Value: String);
var
 m1,m2:Longint;
 s1,s2:string;
begin
 tts1:=tts1+sg1.Cells [acol,arow];
 m1:=length(s1);
 if m1>=8 then
  begin
    m2:=m1-8;
    s2:=copy(s1,m2+1,m1);
    sg1.Cells [acol,arow]:= ';
    sg1.Cells [acol,arow]:=s2;
    exit;
  end;
 if m1<8 then
  begin
   m2:=8-m1;
   s2:=stringofchar('0',m2)+sg1.Cells [acol,arow];
   sg1.Cells [acol,arow]:=s2;
  end;
end;

procedure TForm1.sg1SelectCell(Sender: TObject; ACol, ARow: Integer;
  var CanSelect: Boolean);
begin
tts1:=';
end;

end.

----------------------------------------------
按此在新窗口浏览图片
按此在新窗口浏览图片
作者:
男 jsnjsmc (鱼) ★☆☆☆☆ -
盒子活跃会员
2004/1/13 13:45:41
8楼: 谢谢你,问题基本全部解决了。
----------------------------------------------
-
作者:
男 jsnjsmc (鱼) ★☆☆☆☆ -
盒子活跃会员
2004/1/13 14:18:48
9楼: 我是这样写的,你再帮我看一下:

procedure TfrmLocale.Button2Click(Sender: TObject);
var
  i,J,K:Integer;
  strLine,strcell:string;
  fileHandle:THandle;
  fileName:textfile;
  filestr:string;
begin
  filestr:='c:\test.txt';
  if fileExists(filestr)=false then
    begin
      fileHandle:=FileCreate(filestr);
      fileClose(FileHandle);
    end;

  assignFile(FileName,Filestr);
  Rewrite(fileName);
  for K:=1 to stringGrid1.RowCount - 1 do
    begin
      strLine:=';
      for I:=1 to stringGrid1.ColCount -1 do
        begin
          strcell :=stringGrid1.Cells[i,K];
          for J:=length(strcell) to 8 do
            strcell :=strcell + ' ';
          strLine :=strLine + strcell;//stringGrid1.Cells[i,1];
        end;
      writeLn(fileName,strLine);
    end;
  closeFile(FileName);
end;
----------------------------------------------
-
作者:
男 jsnjsmc (鱼) ★☆☆☆☆ -
盒子活跃会员
2004/1/13 14:19:40
10楼: procedure TfrmLocale.StringGrid1KeyPress(Sender: TObject; var Key: Char);
begin
  if (ord(key) <48) or (ord(key)>57) then
    begin
      showmessage('error');
      key:=chr(0);
    end;
end;
----------------------------------------------
-
作者:
男 bios (阿贡) ★☆☆☆☆ -
盒子中级会员
2004/1/13 15:19:12
11楼: 好的!
----------------------------------------------
按此在新窗口浏览图片
按此在新窗口浏览图片
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行89.84375毫秒 RSS