我维护一个Delphi程序,它使用类型化的二进制文件作为其本机文件格式.从Turbo Delphi升级到Delphi 2010后,存储的记录类型中的所有字符开始以2个字节而不是1个字节存储.
存储的数据类型是char和array[1..5] of char.
所以之前,文件的一部分看起来像:
4C 20 20 20 4E 4E 4E 4E
Run Code Online (Sandbox Code Playgroud)
现在它看起来像:
4C 00 20 00 20 00 20 00 4E 00 4E 00 4E 00 4E 00
Run Code Online (Sandbox Code Playgroud)
首先,为什么这首先发生?
其次,我怎么还能读取我的文件,记住现在宇宙中有旧文件和新文件?
我会在午餐后痴迷地监视这个问题.请随时在评论中询问更多信息.
我有一个Access数据库.让我们假装它是一家宠物商店.
有一张动物桌子.
Animals (animal_id, birth_date, price)
Run Code Online (Sandbox Code Playgroud)
然后是我们销售的不同类型动物的特定表格.
Dogs (animal_id, bark_volume)
Cats (animal_id, collar_size, shedding_rate)
Fish (animal_id)
Run Code Online (Sandbox Code Playgroud)
鱼没有趣味,所以它们没有任何特殊的领域.Fish表存在,因此您知道Animals表中的哪些记录是鱼.
现在,我有一个通用的表格,可以将动物添加到宠物商店.在你获得表格之前,首先要说明你要添加什么样的动物.基于此,表单显示/隐藏字段,更改其记录源,并将字段绑定到适当的数据列.表单从查询DogInfo,CatInfo和FishInfo中提取数据.
现在,当你进入一只狗或一只猫时,一切都很好.记录被添加到动物和狗或猫.
然而,当你进入鱼类时,你得到的只是动物,没有鱼.
可能是什么导致了这个?是不是因为鱼桌上缺少其他栏而引起的?
(让我们撇开这样一个事实,即使用select查询更新表格根本就没有意义.我没想到Access首先让我这么做,但Access的座右铭似乎是"让错误的事情变得容易"做得和正确的事情很难做到."数据库相对简单且不经常使用,并且它比我开始工作之前至少好100倍,所以我真的不太担心这个问题只要我能使它工作.)
关于根据LOC(代码行)数量理解程序需要多长时间,是否有任何广泛的,过于概括的,无用的规则?
(我知道任何规则都是广泛的,过于概括的,而且几乎没用.这没关系.)
(有问题的语言是Delphi,但这并不重要,因为我正在寻找广泛的,过于概括的,几乎无用的规则.)
Python缺乏静态类型使得可以在不导入类的情况下使用和依赖类.你应该导入它们吗?有关系吗?
someclass.py
class SomeClass:
def __init__(self, some_value):
self.some_value = some_value
Run Code Online (Sandbox Code Playgroud)
someclient.py
class SomeClient:
def __init__(self, some_class_instance):
self.some_class_helper = some_class_instance
Run Code Online (Sandbox Code Playgroud)
在这里,功能SomeClient明显依赖于SomeClass或至少表现得像它的东西.但是,someclient.py可以在没有的情况下正常工作import someclass.这个可以吗?使用某些东西而不说任何你甚至使用它的东西都是错误的.
我IEnumerable<SomeClassIWrote>在用户控件中有一个类型的属性.当我在GUI中使用此控件时,.Designer.cs文件包含以下行:
theObject.TheProperty = new SomeClassIWrote[0];
Run Code Online (Sandbox Code Playgroud)
由于某种原因导致编译器警告:
Object of type 'SomeClassIWrote[]' cannot be converted to type
'System.Collections.Generic.IEnumerable`1[SomeClassIWrote]'.
Run Code Online (Sandbox Code Playgroud)
这对我来说是一个谜,因为我一直将数组作为IEnumerables传递,编译器从未抱怨过.
对于它的价值,我有一个为属性指定的默认值null,但在设置默认值之前我得到了相同的错误.
我如何解决这个问题,以便Visual Studio不会抱怨并让我忽略并在每次拉起设计师时继续?
物业代码:
[DefaultValue(null)]
public IEnumerable<SomeClassIWrote> TheProperty {
get {
return _theProperty;
}
set {
if (value == null) {
_theProperty = new SomeClassIWrote[] { };
}
else {
_theProperty = value;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我在项目中有多个类,除了类的名称之外完全相同.基本上,它们代表在运行时从配置文件加载的美化枚举.这些类看起来像这样:
public class ClassName : IEquatable<ClassName> {
public ClassName(string description) {
Description = description;
}
public override bool Equals(object obj) {
return obj != null &&
typeof(ClassName).IsAssignableFrom(obj.GetType()) &&
Equals((ClassName)obj);
}
public bool Equals(ClassName other) {
return other != null &&
Description.Equals(other.Description);
}
public override int GetHashCode() {
return Description.GetHashCode();
}
public override string ToString() {
return Description;
}
public string Description { get; private set; }
}
Run Code Online (Sandbox Code Playgroud)
我认为没有理由复制此文件并多次更改类名.当然,有一种方法可以列出我想要的类,并自动为我创建它们.怎么样?
.net ×2
c# ×2
binary ×1
coding-style ×1
delphi ×1
delphi-2010 ×1
metrics ×1
ms-access ×1
python ×1
winforms ×1