rfcw093b.exe Delphiソース(Delphi5)


program rfc;

uses
  Forms,
  rfcu in 'rfcu.pas' {Form1};

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

unit rfcu;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    OpenDialog1: TOpenDialog;
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private 宣言 }
  public
    { Public 宣言 }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
var
  flname0,flname1 : string;
  tofld,inidir,tofile : string;
  m,m0,m1   : TMemoryStream;
  lstln,lstno,last : word;
  keta0,iro0,retu0,lstln0,md0,lstno0 : word;
  keta1,iro1,retu1,lstln1,md1,lstno1 : word;
  stx,stx0,stx1 : byte;
  ln,ln0,ln1: word;
  afg0,afg1 : array[0..899]of char;
  sfg0,sfg1 : string;
  m0size,m1size,mps,m0ps,m1ps : longint;
    hmytool: hwnd;

begin
    hmytool:=findwindow(nil,'RICOH マイツール');
    form1.top := -100;  form1.Left := -150;
  tofld := extractfilepath(application.exename);
  inidir := tofld + 'myfilex\';
  tofile := tofld + 'myfilex\temp.myx';
  opendialog1.initialdir := inidir;
 try
  m :=TmemoryStream.create;
  m0:=tmemorystream.create;
  m1:=TMemoryStream.Create;
  if opendialog1.execute then begin       //最初のファイル読出
    flname0 := opendialog1.FileName;
    m0.loadfromfile(flname0);
    m0.seek(0,0);m0.read(keta0,2);m0.read(iro0,2);    //各設定読出し
                 m0.read(retu0,2);m0.read(lstln0,2);
    m0.seek(22,1);m0.read(md0,2);
    m0.seek(36,1);m0.read(lstno0,2);
    m0.seek(76,1);m0.read(stx0,1);

    ln  := keta0 +110; ln0 := keta0 + 109;

    while m0.position<m0.size do begin
      if stx0=2 then begin                 //F行を探す
        m0.seek(1,1);m0.read(afg0,ln0);
        sfg0 := trim(afg0);
        break;
      end;
      m0.seek(ln0,1);m0.read(stx0,1);
        if stx0<>2 then begin              //F行が無い時setxバーを0にする
          stx0:=0;
          m0.seek(-1,1);m0.write(stx0,1);
        end;
      sfg0:='';
    end;

    stx0 := 0; m0.Seek(-ln,2);             //最終行よりデータ行を捜す
    while stx0=0 do begin
      m0.read(stx0,1);m0.seek(-(ln+1),1);
    end;
    m0.seek(ln,1);m0.seek(ln,1);
    m0.savetofile(tofile);                // showmessage(inttostr(m0.position));
       postmessage(hmytool, wm_keydown, $52, 0);
       postmessage(hmytool, wm_keydown, $46, 0);
       postmessage(hmytool, wm_keydown, $4c, 0);
       postmessage(hmytool, wm_keydown, vk_return, 0);
       postmessage(hmytool, wm_keydown, $54, 0);
       postmessage(hmytool, wm_keydown, $45, 0);
       postmessage(hmytool, wm_keydown, $4d, 0);
       postmessage(hmytool, wm_keydown, $50, 0);
       postmessage(hmytool, wm_keydown, vk_decimal, 0);
       postmessage(hmytool, wm_keydown, $4d, 0);
       postmessage(hmytool, wm_keydown, $59, 0);
       postmessage(hmytool, wm_keydown, $58, 0);
       postmessage(hmytool, wm_keydown, vk_return, 0);


    lstln := lstln0;
    while lstln<32000 do begin
      if opendialog1.execute then begin       //2番目以降のファイル読出し
        flname1 := opendialog1.FileName;
        m1.loadfromfile(flname1);
        m1size := m1.size;
        m1.seek(0,0);m1.read(keta1,2);
        if keta0<>keta1 then begin
          showmessage('ページサイズが違います'+#10#13+' 結合できません。');
          continue;
        end;
        m1.read(iro1,2);m1.read(retu1,2);m1.read(lstln1,2);
        last := lstln + lstln1;
        if last>32000 then begin
          showmessage('結合行数が32000行を越えます'+#10#13+' 結合できません。');
          continue;
        end;
        m1.seek(22,1);m1.read(md1,2);
        m1.seek(36,1);m1.read(lstno1,2);
        m1.seek(76,1);m1.read(stx1,1);
        ln1 := keta1 + 109;
        sfg1:='';
        while stx1<4 do begin                 //F行を捜す
          if stx1=2 then begin
            m1.seek(1,1);m1.read(afg1,ln1-1);
            sfg1 := trim(afg1);m1.read(stx1,1);
          end else begin
            m1.seek(ln1,1);m1.read(stx1,1);
          end;            
          if m1.position>=m1.size then break;
        end;
        mps:=m1.position;
        if sfg1='' then begin
            m1ps:=m1.size - ln1 - 1;stx:=0;
            while m1ps>146 do begin
              m1.seek(m1ps,0);m1.write(stx,1);
              dec(m1ps,ln1+1);
            end;
        end;
        m1ps:=mps;

        if sfg0<>'' then begin             //元ファイルが表モードの時は
         { if sfg0<>sfg1 then begin
            showmessage('F行が違います。'+#10#13+' 結合出来ません。');
            continue;
          end;   }
          if sfg1<>'' then begin             //元が表で次も表
            m1.Seek(-1,1);m1ps := m1.position;    //showmessage(inttostr(m0ps));
 //           データ行以下のクリアを考える
              m0ps:=m0.position;m.SetSize(m0ps);m.seek(0,0);m0.seek(0,0);
              m.copyfrom(m0,m0ps);    
              m0.LoadFromStream(m);
              m0.seek(m0ps,0);
            m0.copyfrom(m1, m1size - m1ps );

            stx0 := 0; m0.Seek(-ln,2);
            while stx0=0 do begin
              m0.read(stx0,1);m0.seek(-(ln+1),1);
            end;
            m0.seek(ln,1);m0.seek(ln,1);     //元表最終データポジション
          end else begin
            m0.seek(0,2);
            m1.seek(146+ln,0);
            m0.copyfrom(m1, m1.size-m1.position);
          end;
        end else begin                      //元ファイルがEDモードの時は
          m0.seek(0,2);                     
          m1.seek(146+ln,0);                //書き込みはタイトル行の次から
          m0.copyfrom(m1, m1.size-m1.position);   

        end;
        m0size := m0.size;
        if ln<>0 then lstln := (m0size - 146) div ln;lstno := lstln + 10;
        m0.seek(6,0);m0.write(lstln,2);m0.Seek(60,1);m0.write(lstno,2);

        m0.seek(146,0);m0.read(stx0,1);
        while m0.position<m0.size do begin
          if stx0=2 then begin               //F行を探す
            m0.seek(1,1);m0.read(afg0,ln0);
            sfg0 := trim(afg0);
            break;
          end;
          m0.seek(ln0,1);m0.read(stx0,1);
          if stx0<>2 then begin              //F行が無い時setxバーを0にする
            stx0:=0;
            m0.seek(-1,1);m0.write(stx0,1);
          end;
          sfg0:='';
        end;

        stx0 := 0; m0.Seek(-ln,2);           //最終行よりデータ行を捜す
        while stx0=0 do begin
          m0.read(stx0,1);m0.seek(-(ln+1),1);
        end;
        m0.seek(ln,1);m0.seek(ln,1);

        m0.savetofile(tofile);                 //ファイルに書き込み
       postmessage(hmytool, wm_keydown, $52, 0);
       postmessage(hmytool, wm_keydown, $46, 0);
       postmessage(hmytool, wm_keydown, $4c, 0);
       postmessage(hmytool, wm_keydown, vk_return, 0);
       postmessage(hmytool, wm_keydown, $54, 0);
       postmessage(hmytool, wm_keydown, $45, 0);
       postmessage(hmytool, wm_keydown, $4d, 0);
       postmessage(hmytool, wm_keydown, $50, 0);
       postmessage(hmytool, wm_keydown, vk_decimal, 0);
       postmessage(hmytool, wm_keydown, $4d, 0);
       postmessage(hmytool, wm_keydown, $59, 0);
       postmessage(hmytool, wm_keydown, $58, 0);
       postmessage(hmytool, wm_keydown, vk_return, 0);

      end else
        exit;
    end;
  end;

 finally
   m1.free;m0.free;m.free;
 end;

end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  close;
end;

end.

戻る