Delphi 10.4.2 轻松实现Android/IOS txt小说电子书阅读器应用APP翻页效果

Delphi 10.4.2是最新版本的跨平台本机应用开发工具,一套代码可编译到五个操作系统上:iOS、Android、Windows、macOS 和 Linux; 本代码仅仅数十行即可轻松实现Android/IOS txt小说电子书阅读器应用APP翻页效果,颈椎枕轻松开发自己的电子书阅读APP应用:

Delphi源代码下载地址:https://download.csdn.net/download/xyzhan/15647843

unit PageTurnUnit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
  FMX.Controls.Presentation, FMX.ScrollBox, FMX.Memo, FMX.Effects,
  FMX.Filter.Effects, FMX.Objects, FMX.Layouts, FMX.Ani, Data.Bind.GenData,
  Data.Bind.Components, Data.Bind.ObjectScope, Data.Bind.EngExt,
  Fmx.Bind.DBEngExt, System.Rtti, System.Bindings.Outputs, Fmx.Bind.Editors,
  FMX.StdCtrls, FMX.Edit;

type
  TPageTurnSampleForm = class(TForm)
    Memo1: TMemo;
    Memo2: TMemo;
    Swipe: TSwipeTransitionEffect;
    Memo3: TMemo;
    Memo4: TMemo;
    LayoutVisible: TLayout;
    LayoutVirtual: TLayout;
    LayoutGlass: TLayout;
    SwipePoint: TSelectionPoint;
    SwipeAnimation: TPathAnimation;
    PrototypeBindSource1: TPrototypeBindSource;
    BindingsList1: TBindingsList;
    EditLoremIpsum1: TEdit;
    LinkControlToFieldLoremIpsum1: TLinkControlToField;
    procedure FormResize(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure LayoutGlassMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Single);
    procedure LayoutGlassMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Single);
    procedure LayoutGlassMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Single);
    procedure SwipeAnimationProcess(Sender: TObject);
    procedure SwipeAnimationFinish(Sender: TObject);
    procedure LayoutGlassMouseLeave(Sender: TObject);
  private
    { Private declarations }
    FCurPage: Integer;
    procedure FillMemo(memo: TMemo);
    procedure FinishTurn;
    const VisibleLines = 30;
  public
    { Public declarations }
  end;

var
  PageTurnSampleForm: TPageTurnSampleForm;

implementation

{$R *.fmx}

procedure TPageTurnSampleForm.FillMemo(memo: TMemo);
var
  i: Integer;
begin
  Memo.Text := EditLoremIpsum1.Text;
  PrototypeBindSource1.Next;
  for I := 0 to 20 do
    Memo.Text := Memo.Text + Format('Page %d ', [FCurPage]);
  Memo.Text := Memo.Text + EditLoremIpsum1.Text;
  Memo.Text := Memo.Text + EditLoremIpsum1.Text;
  PrototypeBindSource1.Next;
  Inc(FCurPage);
end;

procedure TPageTurnSampleForm.FinishTurn;
begin
  if not Swipe.Enabled then exit;
  if SwipeAnimation.Enabled then exit;

  SwipeAnimation.Path.Clear;
  SwipePoint.Position.Point := PointF(0, 0);
  SwipeAnimation.Path.MoveTo(Swipe.MousePoint);
  if Swipe.MousePoint.X <= ClientWidth - ClientWidth / 4 then
  begin
    SwipeAnimation.Path.LineTo(PointF(Swipe.MousePoint.X / 2, 0));
    SwipeAnimation.Path.LineTo(PointF(0, 0));
  end
  else
  begin
    SwipeAnimation.Path.LineTo(PointF(ClientWidth, 0));
  end;
  SwipeAnimation.Start;
end;


procedure TPageTurnSampleForm.FormCreate(Sender: TObject);
begin
  FCurPage := 1;
  Swipe.CornerPoint := PointF(LayoutGlass.Width, 0);
  Swipe.MousePoint  := PointF(LayoutGlass.Width - 5, 5);
  FillMemo(Memo1);
  FillMemo(Memo2);
  FillMemo(Memo3);
  FillMemo(Memo4);
end;

procedure TPageTurnSampleForm.FormResize(Sender: TObject);
begin
  Memo1.Width := ClientWidth / 2;
  Memo1.Height := ClientHeight;

  Memo2.Width := ClientWidth - Memo1.Width;
  Memo2.Position.X := Memo1.Width;
  Memo2.Height := ClientHeight;

  Memo4.Position := Memo2.Position;
  Memo4.Size := Memo2.Size;

  Memo3.Position := Memo1.Position;
  Memo3.Size := Memo1.Size;
end;

procedure TPageTurnSampleForm.LayoutGlassMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Single);
var
  vmemo: TBitmap;
begin
  Swipe.MousePoint := PointF(x,y);
  Swipe.Enabled := True;
  LayoutVirtual.BringToFront;
  vmemo := LayoutVirtual.MakeScreenshot;
  Swipe.Target.Assign(vmemo);
  vmemo.FlipHorizontal;
  Swipe.Back.Assign(vmemo);
  vmemo.Free;
  LayoutVisible.BringToFront;
end;

procedure TPageTurnSampleForm.LayoutGlassMouseLeave(Sender: TObject);
begin
  FinishTurn;
end;

procedure TPageTurnSampleForm.LayoutGlassMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Single);
begin
  if ssLeft in Shift then
  begin
    Swipe.MousePoint := (TPointF.Create(X,Y));
  end;
end;

procedure TPageTurnSampleForm.LayoutGlassMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Single);
begin
  FinishTurn;
end;

procedure TPageTurnSampleForm.SwipeAnimationFinish(Sender: TObject);
begin
  SwipeAnimation.Enabled := False;
  Swipe.Enabled := False;
  if Swipe.MousePoint.X = 0 then
  begin
    Memo1.Text := Memo3.Text;
    Memo2.Text := Memo4.Text;
    FillMemo(Memo3);
    FillMemo(Memo4);
  end;
end;

procedure TPageTurnSampleForm.SwipeAnimationProcess(Sender: TObject);
begin
  Swipe.MousePoint := SwipePoint.Position.Point;
end;

end.

 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用C#中的System.IO和System.Text命名空间来实现小说txt按章节拆分的功能。 以下是一个简单的示例代码,可以将输入的小说txt文件按照章节拆分为多个单独的txt文件,并按照章节命名: ```csharp using System; using System.IO; using System.Text; namespace NovelSplitter { class Program { static void Main(string[] args) { // 输入小说txt文件路径 Console.Write("请输入小说txt文件路径:"); string filePath = Console.ReadLine(); // 读取小说txt文件内容 string novelText = File.ReadAllText(filePath, Encoding.UTF8); // 按章节拆分并保存为单独的txt文件 string[] chapters = novelText.Split(new string[] { "第" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 1; i < chapters.Length; i++) { string chapterText = chapters[i]; int endIndex = chapterText.IndexOf("章"); string chapterTitle = "第" + chapterText.Substring(0, endIndex) + "章"; chapterText = chapterText.Substring(endIndex + 1); // 将章节文本保存到单独的txt文件中 string chapterFilePath = Path.Combine(Path.GetDirectoryName(filePath), chapterTitle + ".txt"); File.WriteAllText(chapterFilePath, chapterText, Encoding.UTF8); } Console.WriteLine("小说已按章节拆分并保存为单独的txt文件。"); Console.ReadLine(); } } } ``` 使用方法: 1. 将上述代码保存为NovelSplitter.cs文件; 2. 使用Visual Studio或其他C#编译器编译NovelSplitter.cs文件,生成可执行文件NovelSplitter.exe; 3. 打开命令行终端,进入NovelSplitter.exe所在目录; 4. 运行NovelSplitter.exe,按照提示输入小说txt文件路径; 5. 程序将会按照章节拆分小说txt文件,并将各章节保存为单独的txt文件,保存在原小说txt文件所在目录中。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值